From 9d17cdb14c773c1a0397726fa64ef1d45edf1284 Mon Sep 17 00:00:00 2001 From: Samuel Lloyd Date: Wed, 25 Mar 2026 14:20:00 -0600 Subject: [PATCH 01/10] seg_read tests, broken --- unit-tests/SegmentReadWriteT.cpp | 122 +++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 unit-tests/SegmentReadWriteT.cpp diff --git a/unit-tests/SegmentReadWriteT.cpp b/unit-tests/SegmentReadWriteT.cpp new file mode 100644 index 000000000..7d933a6a0 --- /dev/null +++ b/unit-tests/SegmentReadWriteT.cpp @@ -0,0 +1,122 @@ +// -*- mode: c++; c-basic-offset:4 -*- + +// +// Created by slloyd on 3/6/26. +// + +#include +#include + +// #define DODS_DEBUG +#include "util.h" + +#include "run_tests_cppunit.h" +#include "test_config.h" + +using namespace CppUnit; +using namespace std; + +namespace libdap { + +class SegmentReadWriteT : public TestFixture { + util utils; +}; + +public: + SegmentReadWriteT : utils(util::instance()){} //<< probably won't work, revisit + + void setUp() override {} + + void teardown() override {} + + bool gen_large_test_file(uint64_t number, string filepath){ + //use dd to gen and write an extremely large file here + // number should be size in bytes the file should be + int bufferSize = 10000000; + uint64_t count = number / bufferSize; + + const char* command = "dd if=/dev/urandom of="+ filepath +" bs=10M count="+ count; + + std::cout << "Running command: " << command << std::endl; + + // Execute the dd command + int return_code = std::system(command); + + if (return_code == 0) { + std::cout << "dd command executed successfully." << std::endl; + } else { + std::cerr << "dd command failed with return code: " << return_code << std::endl; + } + + return return_code; + } + + void file_cleanup(string filepath){ + // delete the large file that was generated + } + + void write_buffer_to_file(char buffer, string filepath){ + std::streamsize buffer_length = std::strlen(buffer); + + // Open the file in binary mode + std::ofstream outfile(filepath, std::ios::out | std::ios::binary); + + if (!outfile) { + std::cerr << "Error opening file" << std::endl; + return 1; + } + + // Write the buffer to the file + // The write function expects a const char* and the number of bytes to write + outfile.write(buffer, buffer_length); + + // Always close the file when done + outfile.close(); + + std::cout << "Buffer written to output.bin as binary data." << std::endl; + + return 0; + } + + seg_read_test_1(){ + // setup test file + uint64_t bytes = std::pow(2,32); + string filepath = "/tmp/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0){ + CPPUNIT_FAIL("dd command failed with return code: "+ to_string(code)); + } + + // call seg_read on file + char* buff; // <---- suspicious char buffer + std::filebuf fb; + if (fb.open (filepath,std::ios::in)) + { + std::istream is(&fb); + segmented_read(is, buff, bytes); // <---- James, this is the fct in question + fb.close(); + } + + // take seg_read data and write to file + string filepath2 = "/tmp/segReadWriteTest2.bin"; + write_buffer_to_file(buff); + + // assert (compare files) + const char* command = "cmp "+ filepath +" "+ filepath2; + std::cout << "Running command: " << command << std::endl; + int return_code = std::system(command); + CPPUNIT_ASSERT(return_code == 0); + } // end seg_read_test_1() + + CPPUNIT_TEST_SUITE(SegmentReadWriteT); + + CPPUNIT_TEST(seg_read_test_1); //seg_read test 2^32 + CPPUNIT_TEST(...); //seg_read test 2^31 + CPPUNIT_TEST(...); //seg_read test (2^32)-1 byte + CPPUNIT_TEST(...); //seg_write test 2^32 + CPPUNIT_TEST(...); //seg_write test 2^31 + CPPUNIT_TEST(...); //seg_write test (2^32)-1 byte1` + + CPPUNIT_TEST_SUITE_END(); + +} \ No newline at end of file From fff5d6fd411eddfa3af8d27e32b0aed242205b51 Mon Sep 17 00:00:00 2001 From: Samuel Lloyd Date: Thu, 26 Mar 2026 09:14:02 -0600 Subject: [PATCH 02/10] little baby tests --- unit-tests/Makefile.am | 4 +- unit-tests/SegmentReadWriteT.cc | 206 +++++++++++++++++++++++++++++++ unit-tests/SegmentReadWriteT.cpp | 122 ------------------ 3 files changed, 209 insertions(+), 123 deletions(-) create mode 100644 unit-tests/SegmentReadWriteT.cc delete mode 100644 unit-tests/SegmentReadWriteT.cpp diff --git a/unit-tests/Makefile.am b/unit-tests/Makefile.am index bd345b9b3..1283a3937 100644 --- a/unit-tests/Makefile.am +++ b/unit-tests/Makefile.am @@ -89,7 +89,7 @@ UNIT_TESTS = marshT arrayT attrTableT structT sequenceT ddsT dasT \ Int32Test UInt32Test Int64Test UInt64Test Float32Test Float64Test \ D4BaseTypeFactoryTest BaseTypeFactoryTest util_mitTest ErrorTest \ MarshallerFutureTest ConstraintEvaluatorTest MarshallerThreadTest \ - DAPCache3Test BaseTypeTest + DAPCache3Test BaseTypeTest SegmentReadWriteT # Unit tests for DAP4-only code. jhrg 2/4/22 UNIT_TESTS += D4MarshallerTest D4UnMarshallerTest D4DimensionsTest \ @@ -212,6 +212,8 @@ SequenceTest_LDADD = ../tests/libtest-types.a ../libdap.la $(AM_LDADD) SignalHandlerTest_SOURCES = SignalHandlerTest.cc +SegmentReadWriteT_SOURCES = SegmentReadWriteT.cc + arrayT_SOURCES = arrayT.cc arrayT_LDADD = ../tests/libtest-types.a ../libdap.la $(AM_LDADD) diff --git a/unit-tests/SegmentReadWriteT.cc b/unit-tests/SegmentReadWriteT.cc new file mode 100644 index 000000000..12ba70815 --- /dev/null +++ b/unit-tests/SegmentReadWriteT.cc @@ -0,0 +1,206 @@ +// -*- mode: c++; c-basic-offset:4 -*- + +// +// Created by slloyd on 3/6/26. +// + +#include +#include +#include +#include + +// #define DODS_DEBUG +#include "util.h" + +#include "run_tests_cppunit.h" +#include "test_config.h" + +using namespace libdap; +using namespace CppUnit; +using namespace std; + +class SegmentReadWriteT : public TestFixture { + + public: + SegmentReadWriteT() = default; + ~SegmentReadWriteT() = default; + + void setUp() override {} + + void tearDown() override { +#if 0 + dirPath = "/tmp/srwt"; + std::error_code ec; // Use an error code to prevent exceptions + // remove_all attempts to delete the contents and the directory itself recursively + if (fs::remove_all(dirPath, ec) == static_cast(-1) || ec) { + std::cerr << "Error deleting directory " << dirPath << ": " << ec.message() << std::endl; + } else { + std::cout << "Successfully deleted directory: " << dirPath << std::endl; + } +#endif + } + + bool gen_large_test_file(uint64_t size, string filepath) { + // use dd to gen and write an extremely large file here + // number should be size in bytes the file should be + uint64_t bufferSize = 10'000'000; + uint64_t count; + if (size > bufferSize){ + count = size / bufferSize; + } + else { + bufferSize = size; + count = 1; + } + + auto command = "dd if=/dev/urandom of=" + filepath + " bs=10M count=" + to_string(count); + + std::cout << "Running command: " << command << std::endl; + + // Execute the dd command + int return_code = std::system(command.c_str()); + + if (return_code == 0) { + std::cout << "dd command executed successfully." << std::endl; + } else { + std::cerr << "dd command failed with return code: " << return_code << std::endl; + } + + return return_code; + } + + void write_buffer_to_file(char *buffer, uint64_t buffer_length, string filepath) { + // Open the file in binary mode + std::ofstream outfile(filepath, std::ios::out | std::ios::binary); + + if (!outfile) { + DBG(cerr << "Error opening file" << endl); + return; + } + + // Write the buffer to the file + // The write function expects a const char* and the number of bytes to write + outfile.write(buffer, buffer_length); + + // Always close the file when done + outfile.close(); + + DBG(cerr << "Buffer written to output.bin as binary data." << endl); + } + + void seg_read_test_0() { + // setup test file + uint64_t bytes = 10; + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + + // call seg_read on file + vector buff(bytes); + int v = 0; + for (auto &c : buff){ + c = (char) v; + v++; + } + write_buffer_to_file(buff.data(), bytes, filepath); + vector buff2(bytes); + std::filebuf fb; + if (fb.open(filepath, std::ios::in)) { + std::istream is(&fb); + segmented_read(is, buff2.data(), bytes); + fb.close(); + } + CPPUNIT_ASSERT_MESSAGE("buffer should be 0", buff2[0] == 0); + CPPUNIT_ASSERT_MESSAGE("buffer should be 9", buff2[9] == 9); + +#if 0 + // take seg_read data and write to file + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + write_buffer_to_file(buff2.data(), bytes, filepath2); + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + std::cout << "Running command: " << command << std::endl; + int return_code = std::system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); +#endif + } // end seg_read_test_1() + + void seg_write_test_0() { + // setup test file + uint64_t bytes = 10; + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + + // call seg_read on file + vector buff(bytes); + int v = 0; + for (auto &c : buff){ + c = (char) v; + v++; + } + + std::filebuf fb; + if (fb.open(filepath, std::ios::out)) { + std::ostream os(&fb); + segmented_write(os, buff.data(), bytes); + fb.close(); + } + + if (fb.open(filepath, std::ios::in)) { + std::istream is(&fb); + char c; + is.read(&c, 1); + CPPUNIT_ASSERT_MESSAGE("char should be 0", c == 0); + is.seekg(9); + is.read(&c, 1); + CPPUNIT_ASSERT_MESSAGE("char should be 0", c == 9); + fb.close(); + } + + + } // end seg_write_test_1() + + void seg_read_test_1() { + // setup test file + // uint64_t bytes = std::pow(2, 32); + uint64_t bytes = 1000; + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + // call seg_read on file + vector buff(bytes); + std::filebuf fb; + if (fb.open(filepath, std::ios::in)) { + std::istream is(&fb); + segmented_read(is, buff.data(), bytes); + fb.close(); + } + + // take seg_read data and write to file + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + write_buffer_to_file(buff.data(), bytes, filepath2); + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + std::cout << "Running command: " << command << std::endl; + int return_code = std::system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + } // end seg_read_test_1() + + CPPUNIT_TEST_SUITE(SegmentReadWriteT); + + CPPUNIT_TEST(seg_read_test_0); // seg_read test 2^32 + CPPUNIT_TEST(seg_write_test_0); + // CPPUNIT_TEST(...); // seg_read test 2^31 + // CPPUNIT_TEST(...); // seg_read test (2^32)-1 byte + // CPPUNIT_TEST(...); // seg_write test 2^32 + // CPPUNIT_TEST(...); // seg_write test 2^31 + // CPPUNIT_TEST(...); // seg_write test (2^32)-1 byte1` + + CPPUNIT_TEST_SUITE_END(); + }; + + CPPUNIT_TEST_SUITE_REGISTRATION(SegmentReadWriteT); + + int main(int argc, char *argv[]) { return run_tests(argc, argv) ? 0 : 1; } \ No newline at end of file diff --git a/unit-tests/SegmentReadWriteT.cpp b/unit-tests/SegmentReadWriteT.cpp deleted file mode 100644 index 7d933a6a0..000000000 --- a/unit-tests/SegmentReadWriteT.cpp +++ /dev/null @@ -1,122 +0,0 @@ -// -*- mode: c++; c-basic-offset:4 -*- - -// -// Created by slloyd on 3/6/26. -// - -#include -#include - -// #define DODS_DEBUG -#include "util.h" - -#include "run_tests_cppunit.h" -#include "test_config.h" - -using namespace CppUnit; -using namespace std; - -namespace libdap { - -class SegmentReadWriteT : public TestFixture { - util utils; -}; - -public: - SegmentReadWriteT : utils(util::instance()){} //<< probably won't work, revisit - - void setUp() override {} - - void teardown() override {} - - bool gen_large_test_file(uint64_t number, string filepath){ - //use dd to gen and write an extremely large file here - // number should be size in bytes the file should be - int bufferSize = 10000000; - uint64_t count = number / bufferSize; - - const char* command = "dd if=/dev/urandom of="+ filepath +" bs=10M count="+ count; - - std::cout << "Running command: " << command << std::endl; - - // Execute the dd command - int return_code = std::system(command); - - if (return_code == 0) { - std::cout << "dd command executed successfully." << std::endl; - } else { - std::cerr << "dd command failed with return code: " << return_code << std::endl; - } - - return return_code; - } - - void file_cleanup(string filepath){ - // delete the large file that was generated - } - - void write_buffer_to_file(char buffer, string filepath){ - std::streamsize buffer_length = std::strlen(buffer); - - // Open the file in binary mode - std::ofstream outfile(filepath, std::ios::out | std::ios::binary); - - if (!outfile) { - std::cerr << "Error opening file" << std::endl; - return 1; - } - - // Write the buffer to the file - // The write function expects a const char* and the number of bytes to write - outfile.write(buffer, buffer_length); - - // Always close the file when done - outfile.close(); - - std::cout << "Buffer written to output.bin as binary data." << std::endl; - - return 0; - } - - seg_read_test_1(){ - // setup test file - uint64_t bytes = std::pow(2,32); - string filepath = "/tmp/segReadWriteTest1.bin"; - int code = gen_large_test_file(bytes, filepath); - if (code != 0){ - CPPUNIT_FAIL("dd command failed with return code: "+ to_string(code)); - } - - // call seg_read on file - char* buff; // <---- suspicious char buffer - std::filebuf fb; - if (fb.open (filepath,std::ios::in)) - { - std::istream is(&fb); - segmented_read(is, buff, bytes); // <---- James, this is the fct in question - fb.close(); - } - - // take seg_read data and write to file - string filepath2 = "/tmp/segReadWriteTest2.bin"; - write_buffer_to_file(buff); - - // assert (compare files) - const char* command = "cmp "+ filepath +" "+ filepath2; - std::cout << "Running command: " << command << std::endl; - int return_code = std::system(command); - CPPUNIT_ASSERT(return_code == 0); - } // end seg_read_test_1() - - CPPUNIT_TEST_SUITE(SegmentReadWriteT); - - CPPUNIT_TEST(seg_read_test_1); //seg_read test 2^32 - CPPUNIT_TEST(...); //seg_read test 2^31 - CPPUNIT_TEST(...); //seg_read test (2^32)-1 byte - CPPUNIT_TEST(...); //seg_write test 2^32 - CPPUNIT_TEST(...); //seg_write test 2^31 - CPPUNIT_TEST(...); //seg_write test (2^32)-1 byte1` - - CPPUNIT_TEST_SUITE_END(); - -} \ No newline at end of file From c19e93e60c1cbd0933536749bcd1e710cce56136 Mon Sep 17 00:00:00 2001 From: Samuel Lloyd Date: Mon, 30 Mar 2026 15:04:40 -0600 Subject: [PATCH 03/10] 2GB read tests --- unit-tests/SegmentReadWriteT.cc | 146 +++++++++++++++++++++----------- 1 file changed, 98 insertions(+), 48 deletions(-) diff --git a/unit-tests/SegmentReadWriteT.cc b/unit-tests/SegmentReadWriteT.cc index 12ba70815..2d0423676 100644 --- a/unit-tests/SegmentReadWriteT.cc +++ b/unit-tests/SegmentReadWriteT.cc @@ -6,7 +6,7 @@ #include #include -#include +#include // POSIX header #include // #define DODS_DEBUG @@ -25,49 +25,48 @@ class SegmentReadWriteT : public TestFixture { SegmentReadWriteT() = default; ~SegmentReadWriteT() = default; - void setUp() override {} + void setUp() override { + string path_str = "/tmp/srwt"; + // Permissions: read/write/execute for owner (0700) + // You can use S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH for 0755 + mode_t mode = 0700; + + if (mkdir(path_str.c_str(), mode) == 0) { + DBG(cerr << "Directory '" << path_str << "' created successfully." << endl); + } + else{ + DBG(cerr << "Unable to create " << path_str << endl); + } + } // end setUp() void tearDown() override { -#if 0 - dirPath = "/tmp/srwt"; - std::error_code ec; // Use an error code to prevent exceptions - // remove_all attempts to delete the contents and the directory itself recursively - if (fs::remove_all(dirPath, ec) == static_cast(-1) || ec) { - std::cerr << "Error deleting directory " << dirPath << ": " << ec.message() << std::endl; + auto command = "rm -rf /tmp/srwt"; + + int return_code = system(command); + if (return_code == 0) { + DBG(cerr << "rm command executed successfully." << endl); } else { - std::cout << "Successfully deleted directory: " << dirPath << std::endl; + DBG(cerr << "rm command failed with return code: " << return_code << endl); } -#endif - } + } // end tearDown() bool gen_large_test_file(uint64_t size, string filepath) { // use dd to gen and write an extremely large file here - // number should be size in bytes the file should be - uint64_t bufferSize = 10'000'000; - uint64_t count; - if (size > bufferSize){ - count = size / bufferSize; - } - else { - bufferSize = size; - count = 1; - } + auto command = "dd if=/dev/urandom of=" + filepath + " bs=" + to_string(size) + "c iflag=fullblock count=1 status=none"; - auto command = "dd if=/dev/urandom of=" + filepath + " bs=10M count=" + to_string(count); - - std::cout << "Running command: " << command << std::endl; + DBG(cerr << "Running command: " << command << endl); // Execute the dd command - int return_code = std::system(command.c_str()); + int return_code = system(command.c_str()); if (return_code == 0) { - std::cout << "dd command executed successfully." << std::endl; + DBG(cerr << "dd command executed successfully." << endl); } else { - std::cerr << "dd command failed with return code: " << return_code << std::endl; + DBG(cerr << "dd command failed with return code: " << return_code << endl); } return return_code; - } + } // end gen_large_test_file(...) void write_buffer_to_file(char *buffer, uint64_t buffer_length, string filepath) { // Open the file in binary mode @@ -86,7 +85,7 @@ class SegmentReadWriteT : public TestFixture { outfile.close(); DBG(cerr << "Buffer written to output.bin as binary data." << endl); - } + } // end write_buffer_to_file(...) void seg_read_test_0() { // setup test file @@ -110,19 +109,7 @@ class SegmentReadWriteT : public TestFixture { } CPPUNIT_ASSERT_MESSAGE("buffer should be 0", buff2[0] == 0); CPPUNIT_ASSERT_MESSAGE("buffer should be 9", buff2[9] == 9); - -#if 0 - // take seg_read data and write to file - string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; - write_buffer_to_file(buff2.data(), bytes, filepath2); - - // assert (compare files) - auto command = "cmp " + filepath + " " + filepath2; - std::cout << "Running command: " << command << std::endl; - int return_code = std::system(command.c_str()); - CPPUNIT_ASSERT(return_code == 0); -#endif - } // end seg_read_test_1() + } // end seg_read_test_0() void seg_write_test_0() { // setup test file @@ -156,12 +143,11 @@ class SegmentReadWriteT : public TestFixture { } - } // end seg_write_test_1() + } // end seg_write_test_0() void seg_read_test_1() { // setup test file - // uint64_t bytes = std::pow(2, 32); - uint64_t bytes = 1000; + uint64_t bytes = std::pow(2, 31); string filepath = "/tmp/srwt/segReadWriteTest1.bin"; int code = gen_large_test_file(bytes, filepath); if (code != 0) { @@ -183,16 +169,80 @@ class SegmentReadWriteT : public TestFixture { // assert (compare files) auto command = "cmp " + filepath + " " + filepath2; - std::cout << "Running command: " << command << std::endl; + DBG(cerr << "Running command: " << command << endl); int return_code = std::system(command.c_str()); CPPUNIT_ASSERT(return_code == 0); } // end seg_read_test_1() + void seg_read_test_2() { + // setup test file + uint64_t bytes = std::pow(2, 31) - 1; + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + // call seg_read on file + vector buff(bytes); + std::filebuf fb; + if (fb.open(filepath, std::ios::in)) { + std::istream is(&fb); + segmented_read(is, buff.data(), bytes); + fb.close(); + } + + // take seg_read data and write to file + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + write_buffer_to_file(buff.data(), bytes, filepath2); + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = std::system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + } // end seg_read_test_2() + + void seg_read_test_3() { + // setup test file + uint64_t bytes = std::pow(2, 31) + 1; + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + // call seg_read on file + vector buff(bytes); + std::filebuf fb; + if (fb.open(filepath, std::ios::in)) { + std::istream is(&fb); + segmented_read(is, buff.data(), bytes); + fb.close(); + } + + // take seg_read data and write to file + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + write_buffer_to_file(buff.data(), bytes, filepath2); + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = std::system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + } // end seg_read_test_3() + CPPUNIT_TEST_SUITE(SegmentReadWriteT); - CPPUNIT_TEST(seg_read_test_0); // seg_read test 2^32 + // Baby tests + CPPUNIT_TEST(seg_read_test_0); CPPUNIT_TEST(seg_write_test_0); - // CPPUNIT_TEST(...); // seg_read test 2^31 + + // 2GB tests + CPPUNIT_TEST(seg_read_test_1); // seg_read test 2^31 + CPPUNIT_TEST(seg_read_test_2); // seg_read test 2^31 - 1 + CPPUNIT_TEST(seg_read_test_3); // seg_read test 2^31 + 1 + // CPPUNIT_TEST(...); // seg_read test (2^32)-1 byte // CPPUNIT_TEST(...); // seg_write test 2^32 // CPPUNIT_TEST(...); // seg_write test 2^31 From 3dca1a6f131e82efa577d9ea674b089625733120 Mon Sep 17 00:00:00 2001 From: Samuel Lloyd Date: Tue, 31 Mar 2026 11:27:19 -0600 Subject: [PATCH 04/10] 2GB write tests and 4GB tests --- unit-tests/SegmentReadWriteT.cc | 267 +++++++++++++++++++++++++++++++- 1 file changed, 263 insertions(+), 4 deletions(-) diff --git a/unit-tests/SegmentReadWriteT.cc b/unit-tests/SegmentReadWriteT.cc index 2d0423676..a39f65756 100644 --- a/unit-tests/SegmentReadWriteT.cc +++ b/unit-tests/SegmentReadWriteT.cc @@ -87,6 +87,20 @@ class SegmentReadWriteT : public TestFixture { DBG(cerr << "Buffer written to output.bin as binary data." << endl); } // end write_buffer_to_file(...) + vector read_file_to_buffer(string filepath){ + ifstream file(filepath, ios::binary); // Open in binary mode for raw bytes + if (!file) { + DBG(cerr << "Error: Could not open the file " << filepath << endl); + return {}; // Return an empty vector on failure + } + + // Read the entire file content into the vector using iterators + vector file_contents((istreambuf_iterator(file)), istreambuf_iterator()); + + return file_contents; + + } // end read_file_to_buffer(...) + void seg_read_test_0() { // setup test file uint64_t bytes = 10; @@ -232,6 +246,243 @@ class SegmentReadWriteT : public TestFixture { CPPUNIT_ASSERT(return_code == 0); } // end seg_read_test_3() + void seg_write_test_1() { + uint64_t bytes = std::pow(2, 31); + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + vector buffer = read_file_to_buffer(filepath); + filebuf fb; + if (fb.open(filepath2, ios::out)) { + ostream os(&fb); + segmented_write(os, buffer.data(), bytes); + fb.close(); + } + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + + } // end seg_write_test_1() + + void seg_write_test_2() { + uint64_t bytes = std::pow(2, 31) - 1; + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + vector buffer = read_file_to_buffer(filepath); + filebuf fb; + if (fb.open(filepath2, ios::out)) { + ostream os(&fb); + segmented_write(os, buffer.data(), bytes); + fb.close(); + } + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + + } // end seg_write_test_2() + + void seg_write_test_3() { + uint64_t bytes = std::pow(2, 31) + 1; + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + vector buffer = read_file_to_buffer(filepath); + filebuf fb; + if (fb.open(filepath2, ios::out)) { + ostream os(&fb); + segmented_write(os, buffer.data(), bytes); + fb.close(); + } + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + + } // end seg_write_test_3() + + void seg_read_test_4() { + // setup test file + uint64_t bytes = std::pow(2, 32); + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + // call seg_read on file + vector buff(bytes); + std::filebuf fb; + if (fb.open(filepath, std::ios::in)) { + std::istream is(&fb); + segmented_read(is, buff.data(), bytes); + fb.close(); + } + + // take seg_read data and write to file + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + write_buffer_to_file(buff.data(), bytes, filepath2); + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = std::system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + } // end seg_read_test_4() + + void seg_read_test_5() { + // setup test file + uint64_t bytes = std::pow(2, 32) - 1; + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + // call seg_read on file + vector buff(bytes); + std::filebuf fb; + if (fb.open(filepath, std::ios::in)) { + std::istream is(&fb); + segmented_read(is, buff.data(), bytes); + fb.close(); + } + + // take seg_read data and write to file + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + write_buffer_to_file(buff.data(), bytes, filepath2); + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = std::system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + } // end seg_read_test_5() + + void seg_read_test_6() { + // setup test file + uint64_t bytes = std::pow(2, 32) + 1; + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + // call seg_read on file + vector buff(bytes); + std::filebuf fb; + if (fb.open(filepath, std::ios::in)) { + std::istream is(&fb); + segmented_read(is, buff.data(), bytes); + fb.close(); + } + + // take seg_read data and write to file + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + write_buffer_to_file(buff.data(), bytes, filepath2); + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = std::system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + } // end seg_read_test_6() + + void seg_write_test_4() { + uint64_t bytes = std::pow(2, 32); + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + vector buffer = read_file_to_buffer(filepath); + filebuf fb; + if (fb.open(filepath2, ios::out)) { + ostream os(&fb); + segmented_write(os, buffer.data(), bytes); + fb.close(); + } + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + + } // end seg_write_test_4() + + void seg_write_test_5() { + uint64_t bytes = std::pow(2, 32) - 1; + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + vector buffer = read_file_to_buffer(filepath); + filebuf fb; + if (fb.open(filepath2, ios::out)) { + ostream os(&fb); + segmented_write(os, buffer.data(), bytes); + fb.close(); + } + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + + } // end seg_write_test_5() + + void seg_write_test_6() { + uint64_t bytes = std::pow(2, 32) + 1; + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + vector buffer = read_file_to_buffer(filepath); + filebuf fb; + if (fb.open(filepath2, ios::out)) { + ostream os(&fb); + segmented_write(os, buffer.data(), bytes); + fb.close(); + } + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + + } // end seg_write_test_6() + CPPUNIT_TEST_SUITE(SegmentReadWriteT); // Baby tests @@ -243,10 +494,18 @@ class SegmentReadWriteT : public TestFixture { CPPUNIT_TEST(seg_read_test_2); // seg_read test 2^31 - 1 CPPUNIT_TEST(seg_read_test_3); // seg_read test 2^31 + 1 - // CPPUNIT_TEST(...); // seg_read test (2^32)-1 byte - // CPPUNIT_TEST(...); // seg_write test 2^32 - // CPPUNIT_TEST(...); // seg_write test 2^31 - // CPPUNIT_TEST(...); // seg_write test (2^32)-1 byte1` + CPPUNIT_TEST(seg_write_test_1); // seg_write test 2^31 + CPPUNIT_TEST(seg_write_test_2); // seg_write test 2^31 - 1 + CPPUNIT_TEST(seg_write_test_3); // seg_write test 2^31 + 1 + + // 4GB tests + CPPUNIT_TEST(seg_read_test_4); // seg_read test 2^32 + CPPUNIT_TEST(seg_read_test_5); // seg_read test 2^32 - 1 + CPPUNIT_TEST(seg_read_test_6); // seg_read test 2^32 + 1 + + CPPUNIT_TEST(seg_write_test_4); // seg_write test 2^32 + CPPUNIT_TEST(seg_write_test_5); // seg_write test 2^32 - 1 + CPPUNIT_TEST(seg_write_test_6); // seg_write test 2^32 + 1 CPPUNIT_TEST_SUITE_END(); }; From db8815e59827e93b09188caa484b69a232770dbf Mon Sep 17 00:00:00 2001 From: Samuel Lloyd Date: Mon, 6 Apr 2026 09:26:27 -0600 Subject: [PATCH 05/10] draft-PR fix --- unit-tests/SegmentReadWriteT.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unit-tests/SegmentReadWriteT.cc b/unit-tests/SegmentReadWriteT.cc index a39f65756..7d8cc3e25 100644 --- a/unit-tests/SegmentReadWriteT.cc +++ b/unit-tests/SegmentReadWriteT.cc @@ -74,7 +74,7 @@ class SegmentReadWriteT : public TestFixture { if (!outfile) { DBG(cerr << "Error opening file" << endl); - return; + throw std::system_error(errno, generic_category(), "Failed to open " + filepath); } // Write the buffer to the file From b015b5f6d83d4976fae22ed5bc99c0a466d2d02f Mon Sep 17 00:00:00 2001 From: Samuel Lloyd Date: Mon, 6 Apr 2026 09:42:25 -0600 Subject: [PATCH 06/10] clang psuedo fixes --- unit-tests/SegmentReadWriteT.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/unit-tests/SegmentReadWriteT.cc b/unit-tests/SegmentReadWriteT.cc index 7d8cc3e25..713f23f7c 100644 --- a/unit-tests/SegmentReadWriteT.cc +++ b/unit-tests/SegmentReadWriteT.cc @@ -6,8 +6,8 @@ #include #include -#include // POSIX header #include +#include // POSIX header // #define DODS_DEBUG #include "util.h" @@ -512,4 +512,5 @@ class SegmentReadWriteT : public TestFixture { CPPUNIT_TEST_SUITE_REGISTRATION(SegmentReadWriteT); - int main(int argc, char *argv[]) { return run_tests(argc, argv) ? 0 : 1; } \ No newline at end of file + int main(int argc, char *argv[]) { return run_tests(argc, argv) ? 0 : 1; } + \ No newline at end of file From cdd9cf6bd5b9614df5119245516402a684ebe2ac Mon Sep 17 00:00:00 2001 From: Samuel Lloyd Date: Mon, 6 Apr 2026 09:48:33 -0600 Subject: [PATCH 07/10] more clang psuedo fixes --- unit-tests/SegmentReadWriteT.cc | 985 ++++++++++++++++---------------- 1 file changed, 492 insertions(+), 493 deletions(-) diff --git a/unit-tests/SegmentReadWriteT.cc b/unit-tests/SegmentReadWriteT.cc index 713f23f7c..d1427fa86 100644 --- a/unit-tests/SegmentReadWriteT.cc +++ b/unit-tests/SegmentReadWriteT.cc @@ -21,496 +21,495 @@ using namespace std; class SegmentReadWriteT : public TestFixture { - public: - SegmentReadWriteT() = default; - ~SegmentReadWriteT() = default; - - void setUp() override { - string path_str = "/tmp/srwt"; - // Permissions: read/write/execute for owner (0700) - // You can use S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH for 0755 - mode_t mode = 0700; - - if (mkdir(path_str.c_str(), mode) == 0) { - DBG(cerr << "Directory '" << path_str << "' created successfully." << endl); - } - else{ - DBG(cerr << "Unable to create " << path_str << endl); - } - } // end setUp() - - void tearDown() override { - auto command = "rm -rf /tmp/srwt"; - - int return_code = system(command); - if (return_code == 0) { - DBG(cerr << "rm command executed successfully." << endl); - } else { - DBG(cerr << "rm command failed with return code: " << return_code << endl); - } - } // end tearDown() - - bool gen_large_test_file(uint64_t size, string filepath) { - // use dd to gen and write an extremely large file here - auto command = "dd if=/dev/urandom of=" + filepath + " bs=" + to_string(size) + "c iflag=fullblock count=1 status=none"; - - DBG(cerr << "Running command: " << command << endl); - - // Execute the dd command - int return_code = system(command.c_str()); - - if (return_code == 0) { - DBG(cerr << "dd command executed successfully." << endl); - } else { - DBG(cerr << "dd command failed with return code: " << return_code << endl); - } - - return return_code; - } // end gen_large_test_file(...) - - void write_buffer_to_file(char *buffer, uint64_t buffer_length, string filepath) { - // Open the file in binary mode - std::ofstream outfile(filepath, std::ios::out | std::ios::binary); - - if (!outfile) { - DBG(cerr << "Error opening file" << endl); - throw std::system_error(errno, generic_category(), "Failed to open " + filepath); - } - - // Write the buffer to the file - // The write function expects a const char* and the number of bytes to write - outfile.write(buffer, buffer_length); - - // Always close the file when done - outfile.close(); - - DBG(cerr << "Buffer written to output.bin as binary data." << endl); - } // end write_buffer_to_file(...) - - vector read_file_to_buffer(string filepath){ - ifstream file(filepath, ios::binary); // Open in binary mode for raw bytes - if (!file) { - DBG(cerr << "Error: Could not open the file " << filepath << endl); - return {}; // Return an empty vector on failure - } - - // Read the entire file content into the vector using iterators - vector file_contents((istreambuf_iterator(file)), istreambuf_iterator()); - - return file_contents; - - } // end read_file_to_buffer(...) - - void seg_read_test_0() { - // setup test file - uint64_t bytes = 10; - string filepath = "/tmp/srwt/segReadWriteTest1.bin"; - - // call seg_read on file - vector buff(bytes); - int v = 0; - for (auto &c : buff){ - c = (char) v; - v++; - } - write_buffer_to_file(buff.data(), bytes, filepath); - vector buff2(bytes); - std::filebuf fb; - if (fb.open(filepath, std::ios::in)) { - std::istream is(&fb); - segmented_read(is, buff2.data(), bytes); - fb.close(); - } - CPPUNIT_ASSERT_MESSAGE("buffer should be 0", buff2[0] == 0); - CPPUNIT_ASSERT_MESSAGE("buffer should be 9", buff2[9] == 9); - } // end seg_read_test_0() - - void seg_write_test_0() { - // setup test file - uint64_t bytes = 10; - string filepath = "/tmp/srwt/segReadWriteTest1.bin"; - - // call seg_read on file - vector buff(bytes); - int v = 0; - for (auto &c : buff){ - c = (char) v; - v++; - } - - std::filebuf fb; - if (fb.open(filepath, std::ios::out)) { - std::ostream os(&fb); - segmented_write(os, buff.data(), bytes); - fb.close(); - } - - if (fb.open(filepath, std::ios::in)) { - std::istream is(&fb); - char c; - is.read(&c, 1); - CPPUNIT_ASSERT_MESSAGE("char should be 0", c == 0); - is.seekg(9); - is.read(&c, 1); - CPPUNIT_ASSERT_MESSAGE("char should be 0", c == 9); - fb.close(); - } - - - } // end seg_write_test_0() - - void seg_read_test_1() { - // setup test file - uint64_t bytes = std::pow(2, 31); - string filepath = "/tmp/srwt/segReadWriteTest1.bin"; - int code = gen_large_test_file(bytes, filepath); - if (code != 0) { - CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); - } - - // call seg_read on file - vector buff(bytes); - std::filebuf fb; - if (fb.open(filepath, std::ios::in)) { - std::istream is(&fb); - segmented_read(is, buff.data(), bytes); - fb.close(); - } - - // take seg_read data and write to file - string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; - write_buffer_to_file(buff.data(), bytes, filepath2); - - // assert (compare files) - auto command = "cmp " + filepath + " " + filepath2; - DBG(cerr << "Running command: " << command << endl); - int return_code = std::system(command.c_str()); - CPPUNIT_ASSERT(return_code == 0); - } // end seg_read_test_1() - - void seg_read_test_2() { - // setup test file - uint64_t bytes = std::pow(2, 31) - 1; - string filepath = "/tmp/srwt/segReadWriteTest1.bin"; - int code = gen_large_test_file(bytes, filepath); - if (code != 0) { - CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); - } - - // call seg_read on file - vector buff(bytes); - std::filebuf fb; - if (fb.open(filepath, std::ios::in)) { - std::istream is(&fb); - segmented_read(is, buff.data(), bytes); - fb.close(); - } - - // take seg_read data and write to file - string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; - write_buffer_to_file(buff.data(), bytes, filepath2); - - // assert (compare files) - auto command = "cmp " + filepath + " " + filepath2; - DBG(cerr << "Running command: " << command << endl); - int return_code = std::system(command.c_str()); - CPPUNIT_ASSERT(return_code == 0); - } // end seg_read_test_2() - - void seg_read_test_3() { - // setup test file - uint64_t bytes = std::pow(2, 31) + 1; - string filepath = "/tmp/srwt/segReadWriteTest1.bin"; - int code = gen_large_test_file(bytes, filepath); - if (code != 0) { - CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); - } - - // call seg_read on file - vector buff(bytes); - std::filebuf fb; - if (fb.open(filepath, std::ios::in)) { - std::istream is(&fb); - segmented_read(is, buff.data(), bytes); - fb.close(); - } - - // take seg_read data and write to file - string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; - write_buffer_to_file(buff.data(), bytes, filepath2); - - // assert (compare files) - auto command = "cmp " + filepath + " " + filepath2; - DBG(cerr << "Running command: " << command << endl); - int return_code = std::system(command.c_str()); - CPPUNIT_ASSERT(return_code == 0); - } // end seg_read_test_3() - - void seg_write_test_1() { - uint64_t bytes = std::pow(2, 31); - string filepath = "/tmp/srwt/segReadWriteTest1.bin"; - int code = gen_large_test_file(bytes, filepath); - if (code != 0) { - CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); - } - - string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; - vector buffer = read_file_to_buffer(filepath); - filebuf fb; - if (fb.open(filepath2, ios::out)) { - ostream os(&fb); - segmented_write(os, buffer.data(), bytes); - fb.close(); - } - - // assert (compare files) - auto command = "cmp " + filepath + " " + filepath2; - DBG(cerr << "Running command: " << command << endl); - int return_code = system(command.c_str()); - CPPUNIT_ASSERT(return_code == 0); - - } // end seg_write_test_1() - - void seg_write_test_2() { - uint64_t bytes = std::pow(2, 31) - 1; - string filepath = "/tmp/srwt/segReadWriteTest1.bin"; - int code = gen_large_test_file(bytes, filepath); - if (code != 0) { - CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); - } - - string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; - vector buffer = read_file_to_buffer(filepath); - filebuf fb; - if (fb.open(filepath2, ios::out)) { - ostream os(&fb); - segmented_write(os, buffer.data(), bytes); - fb.close(); - } - - // assert (compare files) - auto command = "cmp " + filepath + " " + filepath2; - DBG(cerr << "Running command: " << command << endl); - int return_code = system(command.c_str()); - CPPUNIT_ASSERT(return_code == 0); - - } // end seg_write_test_2() - - void seg_write_test_3() { - uint64_t bytes = std::pow(2, 31) + 1; - string filepath = "/tmp/srwt/segReadWriteTest1.bin"; - int code = gen_large_test_file(bytes, filepath); - if (code != 0) { - CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); - } - - string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; - vector buffer = read_file_to_buffer(filepath); - filebuf fb; - if (fb.open(filepath2, ios::out)) { - ostream os(&fb); - segmented_write(os, buffer.data(), bytes); - fb.close(); - } - - // assert (compare files) - auto command = "cmp " + filepath + " " + filepath2; - DBG(cerr << "Running command: " << command << endl); - int return_code = system(command.c_str()); - CPPUNIT_ASSERT(return_code == 0); - - } // end seg_write_test_3() - - void seg_read_test_4() { - // setup test file - uint64_t bytes = std::pow(2, 32); - string filepath = "/tmp/srwt/segReadWriteTest1.bin"; - int code = gen_large_test_file(bytes, filepath); - if (code != 0) { - CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); - } - - // call seg_read on file - vector buff(bytes); - std::filebuf fb; - if (fb.open(filepath, std::ios::in)) { - std::istream is(&fb); - segmented_read(is, buff.data(), bytes); - fb.close(); - } - - // take seg_read data and write to file - string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; - write_buffer_to_file(buff.data(), bytes, filepath2); - - // assert (compare files) - auto command = "cmp " + filepath + " " + filepath2; - DBG(cerr << "Running command: " << command << endl); - int return_code = std::system(command.c_str()); - CPPUNIT_ASSERT(return_code == 0); - } // end seg_read_test_4() - - void seg_read_test_5() { - // setup test file - uint64_t bytes = std::pow(2, 32) - 1; - string filepath = "/tmp/srwt/segReadWriteTest1.bin"; - int code = gen_large_test_file(bytes, filepath); - if (code != 0) { - CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); - } - - // call seg_read on file - vector buff(bytes); - std::filebuf fb; - if (fb.open(filepath, std::ios::in)) { - std::istream is(&fb); - segmented_read(is, buff.data(), bytes); - fb.close(); - } - - // take seg_read data and write to file - string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; - write_buffer_to_file(buff.data(), bytes, filepath2); - - // assert (compare files) - auto command = "cmp " + filepath + " " + filepath2; - DBG(cerr << "Running command: " << command << endl); - int return_code = std::system(command.c_str()); - CPPUNIT_ASSERT(return_code == 0); - } // end seg_read_test_5() - - void seg_read_test_6() { - // setup test file - uint64_t bytes = std::pow(2, 32) + 1; - string filepath = "/tmp/srwt/segReadWriteTest1.bin"; - int code = gen_large_test_file(bytes, filepath); - if (code != 0) { - CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); - } - - // call seg_read on file - vector buff(bytes); - std::filebuf fb; - if (fb.open(filepath, std::ios::in)) { - std::istream is(&fb); - segmented_read(is, buff.data(), bytes); - fb.close(); - } - - // take seg_read data and write to file - string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; - write_buffer_to_file(buff.data(), bytes, filepath2); - - // assert (compare files) - auto command = "cmp " + filepath + " " + filepath2; - DBG(cerr << "Running command: " << command << endl); - int return_code = std::system(command.c_str()); - CPPUNIT_ASSERT(return_code == 0); - } // end seg_read_test_6() - - void seg_write_test_4() { - uint64_t bytes = std::pow(2, 32); - string filepath = "/tmp/srwt/segReadWriteTest1.bin"; - int code = gen_large_test_file(bytes, filepath); - if (code != 0) { - CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); - } - - string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; - vector buffer = read_file_to_buffer(filepath); - filebuf fb; - if (fb.open(filepath2, ios::out)) { - ostream os(&fb); - segmented_write(os, buffer.data(), bytes); - fb.close(); - } - - // assert (compare files) - auto command = "cmp " + filepath + " " + filepath2; - DBG(cerr << "Running command: " << command << endl); - int return_code = system(command.c_str()); - CPPUNIT_ASSERT(return_code == 0); - - } // end seg_write_test_4() - - void seg_write_test_5() { - uint64_t bytes = std::pow(2, 32) - 1; - string filepath = "/tmp/srwt/segReadWriteTest1.bin"; - int code = gen_large_test_file(bytes, filepath); - if (code != 0) { - CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); - } - - string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; - vector buffer = read_file_to_buffer(filepath); - filebuf fb; - if (fb.open(filepath2, ios::out)) { - ostream os(&fb); - segmented_write(os, buffer.data(), bytes); - fb.close(); - } - - // assert (compare files) - auto command = "cmp " + filepath + " " + filepath2; - DBG(cerr << "Running command: " << command << endl); - int return_code = system(command.c_str()); - CPPUNIT_ASSERT(return_code == 0); - - } // end seg_write_test_5() - - void seg_write_test_6() { - uint64_t bytes = std::pow(2, 32) + 1; - string filepath = "/tmp/srwt/segReadWriteTest1.bin"; - int code = gen_large_test_file(bytes, filepath); - if (code != 0) { - CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); - } - - string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; - vector buffer = read_file_to_buffer(filepath); - filebuf fb; - if (fb.open(filepath2, ios::out)) { - ostream os(&fb); - segmented_write(os, buffer.data(), bytes); - fb.close(); - } - - // assert (compare files) - auto command = "cmp " + filepath + " " + filepath2; - DBG(cerr << "Running command: " << command << endl); - int return_code = system(command.c_str()); - CPPUNIT_ASSERT(return_code == 0); - - } // end seg_write_test_6() - - CPPUNIT_TEST_SUITE(SegmentReadWriteT); - - // Baby tests - CPPUNIT_TEST(seg_read_test_0); - CPPUNIT_TEST(seg_write_test_0); - - // 2GB tests - CPPUNIT_TEST(seg_read_test_1); // seg_read test 2^31 - CPPUNIT_TEST(seg_read_test_2); // seg_read test 2^31 - 1 - CPPUNIT_TEST(seg_read_test_3); // seg_read test 2^31 + 1 - - CPPUNIT_TEST(seg_write_test_1); // seg_write test 2^31 - CPPUNIT_TEST(seg_write_test_2); // seg_write test 2^31 - 1 - CPPUNIT_TEST(seg_write_test_3); // seg_write test 2^31 + 1 - - // 4GB tests - CPPUNIT_TEST(seg_read_test_4); // seg_read test 2^32 - CPPUNIT_TEST(seg_read_test_5); // seg_read test 2^32 - 1 - CPPUNIT_TEST(seg_read_test_6); // seg_read test 2^32 + 1 - - CPPUNIT_TEST(seg_write_test_4); // seg_write test 2^32 - CPPUNIT_TEST(seg_write_test_5); // seg_write test 2^32 - 1 - CPPUNIT_TEST(seg_write_test_6); // seg_write test 2^32 + 1 - - CPPUNIT_TEST_SUITE_END(); - }; - - CPPUNIT_TEST_SUITE_REGISTRATION(SegmentReadWriteT); - - int main(int argc, char *argv[]) { return run_tests(argc, argv) ? 0 : 1; } - \ No newline at end of file +public: + SegmentReadWriteT() = default; + ~SegmentReadWriteT() = default; + + void setUp() override { + string path_str = "/tmp/srwt"; + // Permissions: read/write/execute for owner (0700) + // You can use S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH for 0755 + mode_t mode = 0700; + + if (mkdir(path_str.c_str(), mode) == 0) { + DBG(cerr << "Directory '" << path_str << "' created successfully." << endl); + } + else{ + DBG(cerr << "Unable to create " << path_str << endl); + } + } // end setUp() + + void tearDown() override { + auto command = "rm -rf /tmp/srwt"; + + int return_code = system(command); + if (return_code == 0) { + DBG(cerr << "rm command executed successfully." << endl); + } else { + DBG(cerr << "rm command failed with return code: " << return_code << endl); + } + } // end tearDown() + + bool gen_large_test_file(uint64_t size, string filepath) { + // use dd to gen and write an extremely large file here + auto command = "dd if=/dev/urandom of=" + filepath + " bs=" + to_string(size) + "c iflag=fullblock count=1 status=none"; + + DBG(cerr << "Running command: " << command << endl); + + // Execute the dd command + int return_code = system(command.c_str()); + + if (return_code == 0) { + DBG(cerr << "dd command executed successfully." << endl); + } else { + DBG(cerr << "dd command failed with return code: " << return_code << endl); + } + + return return_code; + } // end gen_large_test_file(...) + + void write_buffer_to_file(char *buffer, uint64_t buffer_length, string filepath) { + // Open the file in binary mode + std::ofstream outfile(filepath, std::ios::out | std::ios::binary); + + if (!outfile) { + DBG(cerr << "Error opening file" << endl); + throw std::system_error(errno, generic_category(), "Failed to open " + filepath); + } + + // Write the buffer to the file + // The write function expects a const char* and the number of bytes to write + outfile.write(buffer, buffer_length); + + // Always close the file when done + outfile.close(); + + DBG(cerr << "Buffer written to output.bin as binary data." << endl); + } // end write_buffer_to_file(...) + + vector read_file_to_buffer(string filepath){ + ifstream file(filepath, ios::binary); // Open in binary mode for raw bytes + if (!file) { + DBG(cerr << "Error: Could not open the file " << filepath << endl); + return {}; // Return an empty vector on failure + } + + // Read the entire file content into the vector using iterators + vector file_contents((istreambuf_iterator(file)), istreambuf_iterator()); + + return file_contents; + + } // end read_file_to_buffer(...) + + void seg_read_test_0() { + // setup test file + uint64_t bytes = 10; + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + + // call seg_read on file + vector buff(bytes); + int v = 0; + for (auto &c : buff){ + c = (char) v; + v++; + } + write_buffer_to_file(buff.data(), bytes, filepath); + vector buff2(bytes); + std::filebuf fb; + if (fb.open(filepath, std::ios::in)) { + std::istream is(&fb); + segmented_read(is, buff2.data(), bytes); + fb.close(); + } + CPPUNIT_ASSERT_MESSAGE("buffer should be 0", buff2[0] == 0); + CPPUNIT_ASSERT_MESSAGE("buffer should be 9", buff2[9] == 9); + } // end seg_read_test_0() + + void seg_write_test_0() { + // setup test file + uint64_t bytes = 10; + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + + // call seg_read on file + vector buff(bytes); + int v = 0; + for (auto &c : buff){ + c = (char) v; + v++; + } + + std::filebuf fb; + if (fb.open(filepath, std::ios::out)) { + std::ostream os(&fb); + segmented_write(os, buff.data(), bytes); + fb.close(); + } + + if (fb.open(filepath, std::ios::in)) { + std::istream is(&fb); + char c; + is.read(&c, 1); + CPPUNIT_ASSERT_MESSAGE("char should be 0", c == 0); + is.seekg(9); + is.read(&c, 1); + CPPUNIT_ASSERT_MESSAGE("char should be 0", c == 9); + fb.close(); + } + + + } // end seg_write_test_0() + + void seg_read_test_1() { + // setup test file + uint64_t bytes = std::pow(2, 31); + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + // call seg_read on file + vector buff(bytes); + std::filebuf fb; + if (fb.open(filepath, std::ios::in)) { + std::istream is(&fb); + segmented_read(is, buff.data(), bytes); + fb.close(); + } + + // take seg_read data and write to file + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + write_buffer_to_file(buff.data(), bytes, filepath2); + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = std::system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + } // end seg_read_test_1() + + void seg_read_test_2() { + // setup test file + uint64_t bytes = std::pow(2, 31) - 1; + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + // call seg_read on file + vector buff(bytes); + std::filebuf fb; + if (fb.open(filepath, std::ios::in)) { + std::istream is(&fb); + segmented_read(is, buff.data(), bytes); + fb.close(); + } + + // take seg_read data and write to file + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + write_buffer_to_file(buff.data(), bytes, filepath2); + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = std::system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + } // end seg_read_test_2() + + void seg_read_test_3() { + // setup test file + uint64_t bytes = std::pow(2, 31) + 1; + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + // call seg_read on file + vector buff(bytes); + std::filebuf fb; + if (fb.open(filepath, std::ios::in)) { + std::istream is(&fb); + segmented_read(is, buff.data(), bytes); + fb.close(); + } + + // take seg_read data and write to file + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + write_buffer_to_file(buff.data(), bytes, filepath2); + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = std::system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + } // end seg_read_test_3() + + void seg_write_test_1() { + uint64_t bytes = std::pow(2, 31); + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + vector buffer = read_file_to_buffer(filepath); + filebuf fb; + if (fb.open(filepath2, ios::out)) { + ostream os(&fb); + segmented_write(os, buffer.data(), bytes); + fb.close(); + } + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + + } // end seg_write_test_1() + + void seg_write_test_2() { + uint64_t bytes = std::pow(2, 31) - 1; + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + vector buffer = read_file_to_buffer(filepath); + filebuf fb; + if (fb.open(filepath2, ios::out)) { + ostream os(&fb); + segmented_write(os, buffer.data(), bytes); + fb.close(); + } + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + + } // end seg_write_test_2() + + void seg_write_test_3() { + uint64_t bytes = std::pow(2, 31) + 1; + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + vector buffer = read_file_to_buffer(filepath); + filebuf fb; + if (fb.open(filepath2, ios::out)) { + ostream os(&fb); + segmented_write(os, buffer.data(), bytes); + fb.close(); + } + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + + } // end seg_write_test_3() + + void seg_read_test_4() { + // setup test file + uint64_t bytes = std::pow(2, 32); + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + // call seg_read on file + vector buff(bytes); + std::filebuf fb; + if (fb.open(filepath, std::ios::in)) { + std::istream is(&fb); + segmented_read(is, buff.data(), bytes); + fb.close(); + } + + // take seg_read data and write to file + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + write_buffer_to_file(buff.data(), bytes, filepath2); + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = std::system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + } // end seg_read_test_4() + + void seg_read_test_5() { + // setup test file + uint64_t bytes = std::pow(2, 32) - 1; + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + // call seg_read on file + vector buff(bytes); + std::filebuf fb; + if (fb.open(filepath, std::ios::in)) { + std::istream is(&fb); + segmented_read(is, buff.data(), bytes); + fb.close(); + } + + // take seg_read data and write to file + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + write_buffer_to_file(buff.data(), bytes, filepath2); + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = std::system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + } // end seg_read_test_5() + + void seg_read_test_6() { + // setup test file + uint64_t bytes = std::pow(2, 32) + 1; + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + // call seg_read on file + vector buff(bytes); + std::filebuf fb; + if (fb.open(filepath, std::ios::in)) { + std::istream is(&fb); + segmented_read(is, buff.data(), bytes); + fb.close(); + } + + // take seg_read data and write to file + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + write_buffer_to_file(buff.data(), bytes, filepath2); + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = std::system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + } // end seg_read_test_6() + + void seg_write_test_4() { + uint64_t bytes = std::pow(2, 32); + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + vector buffer = read_file_to_buffer(filepath); + filebuf fb; + if (fb.open(filepath2, ios::out)) { + ostream os(&fb); + segmented_write(os, buffer.data(), bytes); + fb.close(); + } + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + + } // end seg_write_test_4() + + void seg_write_test_5() { + uint64_t bytes = std::pow(2, 32) - 1; + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + vector buffer = read_file_to_buffer(filepath); + filebuf fb; + if (fb.open(filepath2, ios::out)) { + ostream os(&fb); + segmented_write(os, buffer.data(), bytes); + fb.close(); + } + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + + } // end seg_write_test_5() + + void seg_write_test_6() { + uint64_t bytes = std::pow(2, 32) + 1; + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + vector buffer = read_file_to_buffer(filepath); + filebuf fb; + if (fb.open(filepath2, ios::out)) { + ostream os(&fb); + segmented_write(os, buffer.data(), bytes); + fb.close(); + } + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + + } // end seg_write_test_6() + + CPPUNIT_TEST_SUITE(SegmentReadWriteT); + + // Baby tests + CPPUNIT_TEST(seg_read_test_0); + CPPUNIT_TEST(seg_write_test_0); + + // 2GB tests + CPPUNIT_TEST(seg_read_test_1); // seg_read test 2^31 + CPPUNIT_TEST(seg_read_test_2); // seg_read test 2^31 - 1 + CPPUNIT_TEST(seg_read_test_3); // seg_read test 2^31 + 1 + + CPPUNIT_TEST(seg_write_test_1); // seg_write test 2^31 + CPPUNIT_TEST(seg_write_test_2); // seg_write test 2^31 - 1 + CPPUNIT_TEST(seg_write_test_3); // seg_write test 2^31 + 1 + + // 4GB tests + CPPUNIT_TEST(seg_read_test_4); // seg_read test 2^32 + CPPUNIT_TEST(seg_read_test_5); // seg_read test 2^32 - 1 + CPPUNIT_TEST(seg_read_test_6); // seg_read test 2^32 + 1 + + CPPUNIT_TEST(seg_write_test_4); // seg_write test 2^32 + CPPUNIT_TEST(seg_write_test_5); // seg_write test 2^32 - 1 + CPPUNIT_TEST(seg_write_test_6); // seg_write test 2^32 + 1 + + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(SegmentReadWriteT); + +int main(int argc, char *argv[]) { return run_tests(argc, argv) ? 0 : 1; } From 5aa978ac8ff81fe1ba7d8859a5a2996568d2b400 Mon Sep 17 00:00:00 2001 From: Samuel Lloyd Date: Mon, 6 Apr 2026 09:55:32 -0600 Subject: [PATCH 08/10] more clang psuedo fixes II --- unit-tests/SegmentReadWriteT.cc | 35 ++++++++++++++++----------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/unit-tests/SegmentReadWriteT.cc b/unit-tests/SegmentReadWriteT.cc index d1427fa86..0c76d3332 100644 --- a/unit-tests/SegmentReadWriteT.cc +++ b/unit-tests/SegmentReadWriteT.cc @@ -33,8 +33,7 @@ class SegmentReadWriteT : public TestFixture { if (mkdir(path_str.c_str(), mode) == 0) { DBG(cerr << "Directory '" << path_str << "' created successfully." << endl); - } - else{ + } else { DBG(cerr << "Unable to create " << path_str << endl); } } // end setUp() @@ -52,7 +51,8 @@ class SegmentReadWriteT : public TestFixture { bool gen_large_test_file(uint64_t size, string filepath) { // use dd to gen and write an extremely large file here - auto command = "dd if=/dev/urandom of=" + filepath + " bs=" + to_string(size) + "c iflag=fullblock count=1 status=none"; + auto command = + "dd if=/dev/urandom of=" + filepath + " bs=" + to_string(size) + "c iflag=fullblock count=1 status=none"; DBG(cerr << "Running command: " << command << endl); @@ -87,7 +87,7 @@ class SegmentReadWriteT : public TestFixture { DBG(cerr << "Buffer written to output.bin as binary data." << endl); } // end write_buffer_to_file(...) - vector read_file_to_buffer(string filepath){ + vector read_file_to_buffer(string filepath) { ifstream file(filepath, ios::binary); // Open in binary mode for raw bytes if (!file) { DBG(cerr << "Error: Could not open the file " << filepath << endl); @@ -109,7 +109,7 @@ class SegmentReadWriteT : public TestFixture { // call seg_read on file vector buff(bytes); int v = 0; - for (auto &c : buff){ + for (auto &c : buff) { c = (char) v; v++; } @@ -156,7 +156,6 @@ class SegmentReadWriteT : public TestFixture { fb.close(); } - } // end seg_write_test_0() void seg_read_test_1() { @@ -490,22 +489,22 @@ class SegmentReadWriteT : public TestFixture { CPPUNIT_TEST(seg_write_test_0); // 2GB tests - CPPUNIT_TEST(seg_read_test_1); // seg_read test 2^31 - CPPUNIT_TEST(seg_read_test_2); // seg_read test 2^31 - 1 - CPPUNIT_TEST(seg_read_test_3); // seg_read test 2^31 + 1 + CPPUNIT_TEST(seg_read_test_1); // seg_read test 2^31 + CPPUNIT_TEST(seg_read_test_2); // seg_read test 2^31 - 1 + CPPUNIT_TEST(seg_read_test_3); // seg_read test 2^31 + 1 - CPPUNIT_TEST(seg_write_test_1); // seg_write test 2^31 - CPPUNIT_TEST(seg_write_test_2); // seg_write test 2^31 - 1 - CPPUNIT_TEST(seg_write_test_3); // seg_write test 2^31 + 1 + CPPUNIT_TEST(seg_write_test_1); // seg_write test 2^31 + CPPUNIT_TEST(seg_write_test_2); // seg_write test 2^31 - 1 + CPPUNIT_TEST(seg_write_test_3); // seg_write test 2^31 + 1 // 4GB tests - CPPUNIT_TEST(seg_read_test_4); // seg_read test 2^32 - CPPUNIT_TEST(seg_read_test_5); // seg_read test 2^32 - 1 - CPPUNIT_TEST(seg_read_test_6); // seg_read test 2^32 + 1 + CPPUNIT_TEST(seg_read_test_4); // seg_read test 2^32 + CPPUNIT_TEST(seg_read_test_5); // seg_read test 2^32 - 1 + CPPUNIT_TEST(seg_read_test_6); // seg_read test 2^32 + 1 - CPPUNIT_TEST(seg_write_test_4); // seg_write test 2^32 - CPPUNIT_TEST(seg_write_test_5); // seg_write test 2^32 - 1 - CPPUNIT_TEST(seg_write_test_6); // seg_write test 2^32 + 1 + CPPUNIT_TEST(seg_write_test_4); // seg_write test 2^32 + CPPUNIT_TEST(seg_write_test_5); // seg_write test 2^32 - 1 + CPPUNIT_TEST(seg_write_test_6); // seg_write test 2^32 + 1 CPPUNIT_TEST_SUITE_END(); }; From 159d3d2f8c54925039421fd98da80f761c459070 Mon Sep 17 00:00:00 2001 From: Samuel Lloyd Date: Mon, 6 Apr 2026 09:58:13 -0600 Subject: [PATCH 09/10] more clang psuedo fixes III --- unit-tests/SegmentReadWriteT.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/unit-tests/SegmentReadWriteT.cc b/unit-tests/SegmentReadWriteT.cc index 0c76d3332..77f9e9779 100644 --- a/unit-tests/SegmentReadWriteT.cc +++ b/unit-tests/SegmentReadWriteT.cc @@ -110,7 +110,7 @@ class SegmentReadWriteT : public TestFixture { vector buff(bytes); int v = 0; for (auto &c : buff) { - c = (char) v; + c = (char)v; v++; } write_buffer_to_file(buff.data(), bytes, filepath); @@ -133,8 +133,8 @@ class SegmentReadWriteT : public TestFixture { // call seg_read on file vector buff(bytes); int v = 0; - for (auto &c : buff){ - c = (char) v; + for (auto &c : buff) { + c = (char)v; v++; } From 1ba5c8c12d48e9801261b421b8c0c1024066feca Mon Sep 17 00:00:00 2001 From: Samuel Lloyd Date: Thu, 9 Apr 2026 10:30:59 -0600 Subject: [PATCH 10/10] splitting of the segReadWrite unit tests --- .gitignore | 2 + unit-tests/Makefile.am | 4 +- unit-tests/SegmentReadWriteLT.cc | 453 +++++++++++++++++++++++++++++++ unit-tests/SegmentReadWriteT.cc | 344 +---------------------- 4 files changed, 459 insertions(+), 344 deletions(-) create mode 100644 unit-tests/SegmentReadWriteLT.cc diff --git a/.gitignore b/.gitignore index 2d9b1d868..fe85e14d5 100644 --- a/.gitignore +++ b/.gitignore @@ -227,3 +227,5 @@ install_manifest.txt CPackConfig.cmake CPackSourceConfig.cmake *_CPack_Packages/ +/unit-tests/SegmentReadWriteLT +/unit-tests/SegmentReadWriteT diff --git a/unit-tests/Makefile.am b/unit-tests/Makefile.am index 1283a3937..47b6692f1 100644 --- a/unit-tests/Makefile.am +++ b/unit-tests/Makefile.am @@ -116,7 +116,7 @@ endif # kln 11/19/24 if CPPUNIT if USE_BA -UNIT_TESTS += BigArrayTest +UNIT_TESTS += BigArrayTest SegmentReadWriteLT endif endif @@ -214,6 +214,8 @@ SignalHandlerTest_SOURCES = SignalHandlerTest.cc SegmentReadWriteT_SOURCES = SegmentReadWriteT.cc +SegmentReadWriteLT_SOURCES = SegmentReadWriteLT.cc + arrayT_SOURCES = arrayT.cc arrayT_LDADD = ../tests/libtest-types.a ../libdap.la $(AM_LDADD) diff --git a/unit-tests/SegmentReadWriteLT.cc b/unit-tests/SegmentReadWriteLT.cc new file mode 100644 index 000000000..bed1ed775 --- /dev/null +++ b/unit-tests/SegmentReadWriteLT.cc @@ -0,0 +1,453 @@ +// -*- mode: c++; c-basic-offset:4 -*- + +// +// Created by slloyd on 3/6/26. +// + +#include +#include +#include +#include // POSIX header + +// #define DODS_DEBUG +#include "util.h" + +#include "run_tests_cppunit.h" +#include "test_config.h" + +using namespace libdap; +using namespace CppUnit; +using namespace std; + +class SegmentReadWriteT : public TestFixture { + +public: + SegmentReadWriteT() = default; + ~SegmentReadWriteT() = default; + + void setUp() override { + string path_str = "/tmp/srwt"; + // Permissions: read/write/execute for owner (0700) + // You can use S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH for 0755 + mode_t mode = 0700; + + if (mkdir(path_str.c_str(), mode) == 0) { + DBG(cerr << "Directory '" << path_str << "' created successfully." << endl); + } else { + DBG(cerr << "Unable to create " << path_str << endl); + } + } // end setUp() + + void tearDown() override { + auto command = "rm -rf /tmp/srwt"; + + int return_code = system(command); + if (return_code == 0) { + DBG(cerr << "rm command executed successfully." << endl); + } else { + DBG(cerr << "rm command failed with return code: " << return_code << endl); + } + } // end tearDown() + + bool gen_large_test_file(uint64_t size, string filepath) { + // use dd to gen and write an extremely large file here + auto command = + "dd if=/dev/urandom of=" + filepath + " bs=" + to_string(size) + "c iflag=fullblock count=1 status=none"; + + DBG(cerr << "Running command: " << command << endl); + + // Execute the dd command + int return_code = system(command.c_str()); + + if (return_code == 0) { + DBG(cerr << "dd command executed successfully." << endl); + } else { + DBG(cerr << "dd command failed with return code: " << return_code << endl); + } + + return return_code; + } // end gen_large_test_file(...) + + void write_buffer_to_file(char *buffer, uint64_t buffer_length, string filepath) { + // Open the file in binary mode + std::ofstream outfile(filepath, std::ios::out | std::ios::binary); + + if (!outfile) { + DBG(cerr << "Error opening file" << endl); + throw std::system_error(errno, generic_category(), "Failed to open " + filepath); + } + + // Write the buffer to the file + // The write function expects a const char* and the number of bytes to write + outfile.write(buffer, buffer_length); + + // Always close the file when done + outfile.close(); + + DBG(cerr << "Buffer written to output.bin as binary data." << endl); + } // end write_buffer_to_file(...) + + vector read_file_to_buffer(string filepath) { + ifstream file(filepath, ios::binary); // Open in binary mode for raw bytes + if (!file) { + DBG(cerr << "Error: Could not open the file " << filepath << endl); + return {}; // Return an empty vector on failure + } + + // Read the entire file content into the vector using iterators + vector file_contents((istreambuf_iterator(file)), istreambuf_iterator()); + + return file_contents; + + } // end read_file_to_buffer(...) + + void seg_read_test_1() { + // setup test file + uint64_t bytes = std::pow(2, 31); + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + // call seg_read on file + vector buff(bytes); + std::filebuf fb; + if (fb.open(filepath, std::ios::in)) { + std::istream is(&fb); + segmented_read(is, buff.data(), bytes); + fb.close(); + } + + // take seg_read data and write to file + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + write_buffer_to_file(buff.data(), bytes, filepath2); + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = std::system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + } // end seg_read_test_1() + + void seg_read_test_2() { + // setup test file + uint64_t bytes = std::pow(2, 31) - 1; + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + // call seg_read on file + vector buff(bytes); + std::filebuf fb; + if (fb.open(filepath, std::ios::in)) { + std::istream is(&fb); + segmented_read(is, buff.data(), bytes); + fb.close(); + } + + // take seg_read data and write to file + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + write_buffer_to_file(buff.data(), bytes, filepath2); + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = std::system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + } // end seg_read_test_2() + + void seg_read_test_3() { + // setup test file + uint64_t bytes = std::pow(2, 31) + 1; + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + // call seg_read on file + vector buff(bytes); + std::filebuf fb; + if (fb.open(filepath, std::ios::in)) { + std::istream is(&fb); + segmented_read(is, buff.data(), bytes); + fb.close(); + } + + // take seg_read data and write to file + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + write_buffer_to_file(buff.data(), bytes, filepath2); + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = std::system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + } // end seg_read_test_3() + + void seg_write_test_1() { + uint64_t bytes = std::pow(2, 31); + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + vector buffer = read_file_to_buffer(filepath); + filebuf fb; + if (fb.open(filepath2, ios::out)) { + ostream os(&fb); + segmented_write(os, buffer.data(), bytes); + fb.close(); + } + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + + } // end seg_write_test_1() + + void seg_write_test_2() { + uint64_t bytes = std::pow(2, 31) - 1; + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + vector buffer = read_file_to_buffer(filepath); + filebuf fb; + if (fb.open(filepath2, ios::out)) { + ostream os(&fb); + segmented_write(os, buffer.data(), bytes); + fb.close(); + } + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + + } // end seg_write_test_2() + + void seg_write_test_3() { + uint64_t bytes = std::pow(2, 31) + 1; + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + vector buffer = read_file_to_buffer(filepath); + filebuf fb; + if (fb.open(filepath2, ios::out)) { + ostream os(&fb); + segmented_write(os, buffer.data(), bytes); + fb.close(); + } + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + + } // end seg_write_test_3() + + void seg_read_test_4() { + // setup test file + uint64_t bytes = std::pow(2, 32); + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + // call seg_read on file + vector buff(bytes); + std::filebuf fb; + if (fb.open(filepath, std::ios::in)) { + std::istream is(&fb); + segmented_read(is, buff.data(), bytes); + fb.close(); + } + + // take seg_read data and write to file + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + write_buffer_to_file(buff.data(), bytes, filepath2); + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = std::system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + } // end seg_read_test_4() + + void seg_read_test_5() { + // setup test file + uint64_t bytes = std::pow(2, 32) - 1; + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + // call seg_read on file + vector buff(bytes); + std::filebuf fb; + if (fb.open(filepath, std::ios::in)) { + std::istream is(&fb); + segmented_read(is, buff.data(), bytes); + fb.close(); + } + + // take seg_read data and write to file + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + write_buffer_to_file(buff.data(), bytes, filepath2); + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = std::system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + } // end seg_read_test_5() + + void seg_read_test_6() { + // setup test file + uint64_t bytes = std::pow(2, 32) + 1; + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + // call seg_read on file + vector buff(bytes); + std::filebuf fb; + if (fb.open(filepath, std::ios::in)) { + std::istream is(&fb); + segmented_read(is, buff.data(), bytes); + fb.close(); + } + + // take seg_read data and write to file + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + write_buffer_to_file(buff.data(), bytes, filepath2); + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = std::system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + } // end seg_read_test_6() + + void seg_write_test_4() { + uint64_t bytes = std::pow(2, 32); + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + vector buffer = read_file_to_buffer(filepath); + filebuf fb; + if (fb.open(filepath2, ios::out)) { + ostream os(&fb); + segmented_write(os, buffer.data(), bytes); + fb.close(); + } + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + + } // end seg_write_test_4() + + void seg_write_test_5() { + uint64_t bytes = std::pow(2, 32) - 1; + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + vector buffer = read_file_to_buffer(filepath); + filebuf fb; + if (fb.open(filepath2, ios::out)) { + ostream os(&fb); + segmented_write(os, buffer.data(), bytes); + fb.close(); + } + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + + } // end seg_write_test_5() + + void seg_write_test_6() { + uint64_t bytes = std::pow(2, 32) + 1; + string filepath = "/tmp/srwt/segReadWriteTest1.bin"; + int code = gen_large_test_file(bytes, filepath); + if (code != 0) { + CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); + } + + string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; + vector buffer = read_file_to_buffer(filepath); + filebuf fb; + if (fb.open(filepath2, ios::out)) { + ostream os(&fb); + segmented_write(os, buffer.data(), bytes); + fb.close(); + } + + // assert (compare files) + auto command = "cmp " + filepath + " " + filepath2; + DBG(cerr << "Running command: " << command << endl); + int return_code = system(command.c_str()); + CPPUNIT_ASSERT(return_code == 0); + + } // end seg_write_test_6() + + CPPUNIT_TEST_SUITE(SegmentReadWriteT); + + // 2GB tests + CPPUNIT_TEST(seg_read_test_1); // seg_read test 2^31 + CPPUNIT_TEST(seg_read_test_2); // seg_read test 2^31 - 1 + CPPUNIT_TEST(seg_read_test_3); // seg_read test 2^31 + 1 + + CPPUNIT_TEST(seg_write_test_1); // seg_write test 2^31 + CPPUNIT_TEST(seg_write_test_2); // seg_write test 2^31 - 1 + CPPUNIT_TEST(seg_write_test_3); // seg_write test 2^31 + 1 + + // 4GB tests + CPPUNIT_TEST(seg_read_test_4); // seg_read test 2^32 + CPPUNIT_TEST(seg_read_test_5); // seg_read test 2^32 - 1 + CPPUNIT_TEST(seg_read_test_6); // seg_read test 2^32 + 1 + + CPPUNIT_TEST(seg_write_test_4); // seg_write test 2^32 + CPPUNIT_TEST(seg_write_test_5); // seg_write test 2^32 - 1 + CPPUNIT_TEST(seg_write_test_6); // seg_write test 2^32 + 1 + + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(SegmentReadWriteT); + +int main(int argc, char *argv[]) { return run_tests(argc, argv) ? 0 : 1; } diff --git a/unit-tests/SegmentReadWriteT.cc b/unit-tests/SegmentReadWriteT.cc index 77f9e9779..72654410d 100644 --- a/unit-tests/SegmentReadWriteT.cc +++ b/unit-tests/SegmentReadWriteT.cc @@ -158,354 +158,12 @@ class SegmentReadWriteT : public TestFixture { } // end seg_write_test_0() - void seg_read_test_1() { - // setup test file - uint64_t bytes = std::pow(2, 31); - string filepath = "/tmp/srwt/segReadWriteTest1.bin"; - int code = gen_large_test_file(bytes, filepath); - if (code != 0) { - CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); - } - - // call seg_read on file - vector buff(bytes); - std::filebuf fb; - if (fb.open(filepath, std::ios::in)) { - std::istream is(&fb); - segmented_read(is, buff.data(), bytes); - fb.close(); - } - - // take seg_read data and write to file - string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; - write_buffer_to_file(buff.data(), bytes, filepath2); - - // assert (compare files) - auto command = "cmp " + filepath + " " + filepath2; - DBG(cerr << "Running command: " << command << endl); - int return_code = std::system(command.c_str()); - CPPUNIT_ASSERT(return_code == 0); - } // end seg_read_test_1() - - void seg_read_test_2() { - // setup test file - uint64_t bytes = std::pow(2, 31) - 1; - string filepath = "/tmp/srwt/segReadWriteTest1.bin"; - int code = gen_large_test_file(bytes, filepath); - if (code != 0) { - CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); - } - - // call seg_read on file - vector buff(bytes); - std::filebuf fb; - if (fb.open(filepath, std::ios::in)) { - std::istream is(&fb); - segmented_read(is, buff.data(), bytes); - fb.close(); - } - - // take seg_read data and write to file - string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; - write_buffer_to_file(buff.data(), bytes, filepath2); - - // assert (compare files) - auto command = "cmp " + filepath + " " + filepath2; - DBG(cerr << "Running command: " << command << endl); - int return_code = std::system(command.c_str()); - CPPUNIT_ASSERT(return_code == 0); - } // end seg_read_test_2() - - void seg_read_test_3() { - // setup test file - uint64_t bytes = std::pow(2, 31) + 1; - string filepath = "/tmp/srwt/segReadWriteTest1.bin"; - int code = gen_large_test_file(bytes, filepath); - if (code != 0) { - CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); - } - - // call seg_read on file - vector buff(bytes); - std::filebuf fb; - if (fb.open(filepath, std::ios::in)) { - std::istream is(&fb); - segmented_read(is, buff.data(), bytes); - fb.close(); - } - - // take seg_read data and write to file - string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; - write_buffer_to_file(buff.data(), bytes, filepath2); - - // assert (compare files) - auto command = "cmp " + filepath + " " + filepath2; - DBG(cerr << "Running command: " << command << endl); - int return_code = std::system(command.c_str()); - CPPUNIT_ASSERT(return_code == 0); - } // end seg_read_test_3() - - void seg_write_test_1() { - uint64_t bytes = std::pow(2, 31); - string filepath = "/tmp/srwt/segReadWriteTest1.bin"; - int code = gen_large_test_file(bytes, filepath); - if (code != 0) { - CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); - } - - string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; - vector buffer = read_file_to_buffer(filepath); - filebuf fb; - if (fb.open(filepath2, ios::out)) { - ostream os(&fb); - segmented_write(os, buffer.data(), bytes); - fb.close(); - } - - // assert (compare files) - auto command = "cmp " + filepath + " " + filepath2; - DBG(cerr << "Running command: " << command << endl); - int return_code = system(command.c_str()); - CPPUNIT_ASSERT(return_code == 0); - - } // end seg_write_test_1() - - void seg_write_test_2() { - uint64_t bytes = std::pow(2, 31) - 1; - string filepath = "/tmp/srwt/segReadWriteTest1.bin"; - int code = gen_large_test_file(bytes, filepath); - if (code != 0) { - CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); - } - - string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; - vector buffer = read_file_to_buffer(filepath); - filebuf fb; - if (fb.open(filepath2, ios::out)) { - ostream os(&fb); - segmented_write(os, buffer.data(), bytes); - fb.close(); - } - - // assert (compare files) - auto command = "cmp " + filepath + " " + filepath2; - DBG(cerr << "Running command: " << command << endl); - int return_code = system(command.c_str()); - CPPUNIT_ASSERT(return_code == 0); - - } // end seg_write_test_2() - - void seg_write_test_3() { - uint64_t bytes = std::pow(2, 31) + 1; - string filepath = "/tmp/srwt/segReadWriteTest1.bin"; - int code = gen_large_test_file(bytes, filepath); - if (code != 0) { - CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); - } - - string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; - vector buffer = read_file_to_buffer(filepath); - filebuf fb; - if (fb.open(filepath2, ios::out)) { - ostream os(&fb); - segmented_write(os, buffer.data(), bytes); - fb.close(); - } - - // assert (compare files) - auto command = "cmp " + filepath + " " + filepath2; - DBG(cerr << "Running command: " << command << endl); - int return_code = system(command.c_str()); - CPPUNIT_ASSERT(return_code == 0); - - } // end seg_write_test_3() - - void seg_read_test_4() { - // setup test file - uint64_t bytes = std::pow(2, 32); - string filepath = "/tmp/srwt/segReadWriteTest1.bin"; - int code = gen_large_test_file(bytes, filepath); - if (code != 0) { - CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); - } - - // call seg_read on file - vector buff(bytes); - std::filebuf fb; - if (fb.open(filepath, std::ios::in)) { - std::istream is(&fb); - segmented_read(is, buff.data(), bytes); - fb.close(); - } - - // take seg_read data and write to file - string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; - write_buffer_to_file(buff.data(), bytes, filepath2); - - // assert (compare files) - auto command = "cmp " + filepath + " " + filepath2; - DBG(cerr << "Running command: " << command << endl); - int return_code = std::system(command.c_str()); - CPPUNIT_ASSERT(return_code == 0); - } // end seg_read_test_4() - - void seg_read_test_5() { - // setup test file - uint64_t bytes = std::pow(2, 32) - 1; - string filepath = "/tmp/srwt/segReadWriteTest1.bin"; - int code = gen_large_test_file(bytes, filepath); - if (code != 0) { - CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); - } - - // call seg_read on file - vector buff(bytes); - std::filebuf fb; - if (fb.open(filepath, std::ios::in)) { - std::istream is(&fb); - segmented_read(is, buff.data(), bytes); - fb.close(); - } - - // take seg_read data and write to file - string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; - write_buffer_to_file(buff.data(), bytes, filepath2); - - // assert (compare files) - auto command = "cmp " + filepath + " " + filepath2; - DBG(cerr << "Running command: " << command << endl); - int return_code = std::system(command.c_str()); - CPPUNIT_ASSERT(return_code == 0); - } // end seg_read_test_5() - - void seg_read_test_6() { - // setup test file - uint64_t bytes = std::pow(2, 32) + 1; - string filepath = "/tmp/srwt/segReadWriteTest1.bin"; - int code = gen_large_test_file(bytes, filepath); - if (code != 0) { - CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); - } - - // call seg_read on file - vector buff(bytes); - std::filebuf fb; - if (fb.open(filepath, std::ios::in)) { - std::istream is(&fb); - segmented_read(is, buff.data(), bytes); - fb.close(); - } - - // take seg_read data and write to file - string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; - write_buffer_to_file(buff.data(), bytes, filepath2); - - // assert (compare files) - auto command = "cmp " + filepath + " " + filepath2; - DBG(cerr << "Running command: " << command << endl); - int return_code = std::system(command.c_str()); - CPPUNIT_ASSERT(return_code == 0); - } // end seg_read_test_6() - - void seg_write_test_4() { - uint64_t bytes = std::pow(2, 32); - string filepath = "/tmp/srwt/segReadWriteTest1.bin"; - int code = gen_large_test_file(bytes, filepath); - if (code != 0) { - CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); - } - - string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; - vector buffer = read_file_to_buffer(filepath); - filebuf fb; - if (fb.open(filepath2, ios::out)) { - ostream os(&fb); - segmented_write(os, buffer.data(), bytes); - fb.close(); - } - - // assert (compare files) - auto command = "cmp " + filepath + " " + filepath2; - DBG(cerr << "Running command: " << command << endl); - int return_code = system(command.c_str()); - CPPUNIT_ASSERT(return_code == 0); - - } // end seg_write_test_4() - - void seg_write_test_5() { - uint64_t bytes = std::pow(2, 32) - 1; - string filepath = "/tmp/srwt/segReadWriteTest1.bin"; - int code = gen_large_test_file(bytes, filepath); - if (code != 0) { - CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); - } - - string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; - vector buffer = read_file_to_buffer(filepath); - filebuf fb; - if (fb.open(filepath2, ios::out)) { - ostream os(&fb); - segmented_write(os, buffer.data(), bytes); - fb.close(); - } - - // assert (compare files) - auto command = "cmp " + filepath + " " + filepath2; - DBG(cerr << "Running command: " << command << endl); - int return_code = system(command.c_str()); - CPPUNIT_ASSERT(return_code == 0); - - } // end seg_write_test_5() - - void seg_write_test_6() { - uint64_t bytes = std::pow(2, 32) + 1; - string filepath = "/tmp/srwt/segReadWriteTest1.bin"; - int code = gen_large_test_file(bytes, filepath); - if (code != 0) { - CPPUNIT_FAIL("dd command failed with return code: " + to_string(code)); - } - - string filepath2 = "/tmp/srwt/segReadWriteTest2.bin"; - vector buffer = read_file_to_buffer(filepath); - filebuf fb; - if (fb.open(filepath2, ios::out)) { - ostream os(&fb); - segmented_write(os, buffer.data(), bytes); - fb.close(); - } - - // assert (compare files) - auto command = "cmp " + filepath + " " + filepath2; - DBG(cerr << "Running command: " << command << endl); - int return_code = system(command.c_str()); - CPPUNIT_ASSERT(return_code == 0); - - } // end seg_write_test_6() - CPPUNIT_TEST_SUITE(SegmentReadWriteT); - // Baby tests + // tests CPPUNIT_TEST(seg_read_test_0); CPPUNIT_TEST(seg_write_test_0); - // 2GB tests - CPPUNIT_TEST(seg_read_test_1); // seg_read test 2^31 - CPPUNIT_TEST(seg_read_test_2); // seg_read test 2^31 - 1 - CPPUNIT_TEST(seg_read_test_3); // seg_read test 2^31 + 1 - - CPPUNIT_TEST(seg_write_test_1); // seg_write test 2^31 - CPPUNIT_TEST(seg_write_test_2); // seg_write test 2^31 - 1 - CPPUNIT_TEST(seg_write_test_3); // seg_write test 2^31 + 1 - - // 4GB tests - CPPUNIT_TEST(seg_read_test_4); // seg_read test 2^32 - CPPUNIT_TEST(seg_read_test_5); // seg_read test 2^32 - 1 - CPPUNIT_TEST(seg_read_test_6); // seg_read test 2^32 + 1 - - CPPUNIT_TEST(seg_write_test_4); // seg_write test 2^32 - CPPUNIT_TEST(seg_write_test_5); // seg_write test 2^32 - 1 - CPPUNIT_TEST(seg_write_test_6); // seg_write test 2^32 + 1 - CPPUNIT_TEST_SUITE_END(); };