mirror of
https://github.com/akuker/RASCSI.git
synced 2026-04-25 14:26:28 +00:00
* Add options to only run INQUIRY and to scan the bus to scsidump
This commit is contained in:
@@ -65,7 +65,7 @@ TEST(GpiobusRaspberry, GetDtRanges)
|
||||
EXPECT_EQ(0x20000000, GPIOBUS_Raspberry::bcm_host_get_peripheral_address());
|
||||
DeleteTempFile("/proc/device-tree/soc/ranges");
|
||||
|
||||
CleanUpAllTempFiles();
|
||||
remove_all(test_data_temp_path);
|
||||
}
|
||||
|
||||
TEST(GpiobusRaspberry, GetDat)
|
||||
|
||||
+19
-25
@@ -1,72 +1,66 @@
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// SCSI Target Emulator PiSCSI
|
||||
// for Raspberry Pi
|
||||
//
|
||||
// Copyright (C) 2022 akuker
|
||||
// Copyright (C) 2023 Uwe Seimet
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#include "mocks.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "scsidump/scsidump_core.h"
|
||||
#include "test/test_shared.h"
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
using namespace filesystem;
|
||||
|
||||
class TestableScsidump : public ScsiDump
|
||||
{
|
||||
public:
|
||||
static void PublicGeneratePropertiesFile(const string& filename, const inquiry_info_t& inq_info)
|
||||
{
|
||||
ScsiDump::GeneratePropertiesFile(filename, inq_info);
|
||||
}
|
||||
};
|
||||
|
||||
TEST(ScsiDumpTest, GeneratePropertiesFile)
|
||||
{
|
||||
// Basic test
|
||||
const string prop_file_name = "test.properties";
|
||||
ScsiDump::inquiry_info_t test_data = {
|
||||
// Basic test
|
||||
auto filename = CreateTempFile(0);
|
||||
ScsiDump::inquiry_info_t test_data = {
|
||||
.vendor = "PISCSI", .product = "TEST PRODUCT", .revision = "REV1", .sector_size = 1000, .capacity = 100};
|
||||
TestableScsidump::PublicGeneratePropertiesFile("test", test_data);
|
||||
test_data.GeneratePropertiesFile(filename);
|
||||
|
||||
string expected_str = "{\n"
|
||||
" \"vendor\": \"PISCSI\",\n"
|
||||
" \"product\": \"TEST PRODUCT\",\n"
|
||||
" \"revision\": \"REV1\",\n"
|
||||
" \"block_size\": \"1000\",\n}"
|
||||
" \"block_size\": \"1000\"\n}"
|
||||
"\n";
|
||||
EXPECT_EQ(ReadTempFileToString(prop_file_name), expected_str);
|
||||
EXPECT_EQ(expected_str, ReadTempFileToString(filename));
|
||||
|
||||
// Long string test
|
||||
filename = CreateTempFile(0);
|
||||
test_data = {.vendor = "01234567",
|
||||
.product = "0123456789ABCDEF",
|
||||
.revision = "0123",
|
||||
.sector_size = UINT32_MAX,
|
||||
.capacity = UINT64_MAX};
|
||||
TestableScsidump::PublicGeneratePropertiesFile("test", test_data);
|
||||
test_data.GeneratePropertiesFile(filename);
|
||||
|
||||
expected_str = "{\n"
|
||||
" \"vendor\": \"01234567\",\n"
|
||||
" \"product\": \"0123456789ABCDEF\",\n"
|
||||
" \"revision\": \"0123\",\n"
|
||||
" \"block_size\": \"4294967295\",\n"
|
||||
" \"block_size\": \"4294967295\"\n"
|
||||
"}\n";
|
||||
EXPECT_EQ(ReadTempFileToString(prop_file_name), expected_str);
|
||||
EXPECT_EQ(expected_str, ReadTempFileToString(filename));
|
||||
remove(filename);
|
||||
|
||||
// Empty data test
|
||||
filename = CreateTempFile(0);
|
||||
test_data = {.vendor = "", .product = "", .revision = "", .sector_size = 0, .capacity = 0};
|
||||
TestableScsidump::PublicGeneratePropertiesFile("test", test_data);
|
||||
test_data.GeneratePropertiesFile(filename);
|
||||
|
||||
expected_str = "{\n"
|
||||
" \"vendor\": \"\",\n"
|
||||
" \"product\": \"\",\n"
|
||||
" \"revision\": \"\",\n"
|
||||
" \"block_size\": \"0\",\n"
|
||||
" \"block_size\": \"0\"\n"
|
||||
"}\n";
|
||||
EXPECT_EQ(ReadTempFileToString(prop_file_name), expected_str);
|
||||
EXPECT_EQ(expected_str, ReadTempFileToString(filename));
|
||||
remove(filename);
|
||||
}
|
||||
|
||||
@@ -121,24 +121,20 @@ void CreateTempFileWithData(const string& filename, vector<uint8_t>& data)
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
// TODO Move this code, it is not shared
|
||||
void DeleteTempFile(const string& filename)
|
||||
{
|
||||
path temp_file = test_data_temp_path;
|
||||
temp_file += path(filename);
|
||||
remove(temp_file);
|
||||
}
|
||||
|
||||
void CleanUpAllTempFiles()
|
||||
{
|
||||
remove_all(test_data_temp_path);
|
||||
path temp_file = test_data_temp_path;
|
||||
temp_file += path(filename);
|
||||
remove(temp_file);
|
||||
}
|
||||
|
||||
string ReadTempFileToString(const string& filename)
|
||||
{
|
||||
const path temp_file = test_data_temp_path / path(filename);
|
||||
ifstream in_fs(temp_file);
|
||||
ifstream in(temp_file);
|
||||
stringstream buffer;
|
||||
buffer << in_fs.rdbuf();
|
||||
buffer << in.rdbuf();
|
||||
|
||||
return buffer.str();
|
||||
}
|
||||
|
||||
@@ -35,8 +35,6 @@ path CreateTempFileWithData(span<const byte>);
|
||||
void CreateTempFileWithData(const string&, vector<uint8_t>&);
|
||||
|
||||
void DeleteTempFile(const string&);
|
||||
// Call this at the end of every test case to make sure things are cleaned up
|
||||
void CleanUpAllTempFiles();
|
||||
|
||||
string ReadTempFileToString(const string& filename);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user