|
| 1 | +#include <filesystem> |
| 2 | +#include "gtest/gtest.h" |
| 3 | + |
| 4 | +#include <cstdlib> |
| 5 | +#include <cstdio> |
| 6 | +#include <string> |
| 7 | +#include <fstream> |
| 8 | +#include <sys/stat.h> |
| 9 | +#include "Hummbee/hummbee.h" |
| 10 | + |
| 11 | +using namespace std; |
| 12 | +using namespace std::filesystem; |
| 13 | +using namespace casacore; |
| 14 | + |
| 15 | +namespace test{ |
| 16 | + const path goldDir = current_path() / "gold_standard"; |
| 17 | + |
| 18 | +// Function to run the shell script |
| 19 | +std::string run_shell_script(const std::string& imagename) { |
| 20 | + // Ensure that the script is executable |
| 21 | + system("chmod +x ./libra_htclean.sh"); |
| 22 | + system("chmod +x ./runapp.sh"); |
| 23 | + |
| 24 | + std::string command = "./libra_htclean.sh -i " + imagename + " -n 3 -p libra_htclean.def -L ../../../../install/bin/ -l LOGS"; |
| 25 | + char buffer[128]; |
| 26 | + std::string result = ""; |
| 27 | + FILE* fp = popen(command.c_str(), "r"); |
| 28 | + if (fp == nullptr) { |
| 29 | + return "Error running script"; |
| 30 | + } |
| 31 | + while (fgets(buffer, sizeof(buffer), fp) != nullptr) { |
| 32 | + result += buffer; |
| 33 | + } |
| 34 | + fclose(fp); |
| 35 | + return result; |
| 36 | +} |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | +TEST(HtcleanTest, Loops) { |
| 41 | + // Get the test name |
| 42 | + string testName = ::testing::UnitTest::GetInstance()->current_test_info()->name(); |
| 43 | + |
| 44 | + // Create a unique directory for this test case |
| 45 | + path testDir = current_path() / testName; |
| 46 | + |
| 47 | + // create dir AppLevelSNRPSF |
| 48 | + std::filesystem::create_directory(testDir); |
| 49 | + |
| 50 | + //copy over CYGTST.corespiral.ms from gold_standard to AppLevelSNRPSF |
| 51 | + std::filesystem::copy(goldDir/"CYGTST.corespiral.ms", testDir/"CYGTST.corespiral.ms", copy_options::recursive); |
| 52 | + //copy over 4k_nosquint.cfc from gold_standard to AppLevelSNRPSF |
| 53 | + std::filesystem::copy(goldDir/"4k_nosquint.cfc", testDir/"4k_nosquint.cfc", copy_options::recursive); |
| 54 | + // copy the input .def |
| 55 | + std::filesystem::copy(goldDir/"libra_htclean.def", testDir/"libra_htclean.def", copy_options::recursive); |
| 56 | + // copy htclean scripts |
| 57 | + std::filesystem::copy(goldDir/"../../../../frameworks/htclean/libra_htclean.sh", testDir/"libra_htclean.sh", copy_options::recursive); |
| 58 | + std::filesystem::copy(goldDir/"../../../../frameworks/htclean/runapp.sh", testDir/"runapp.sh", copy_options::recursive); |
| 59 | + //Step into test dir |
| 60 | + std::filesystem::current_path(testDir); |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | + string imagename = "cygA"; |
| 65 | + // Run the script |
| 66 | + string output = run_shell_script(imagename); |
| 67 | + |
| 68 | + // Check that the images are generated |
| 69 | + path p1("cygA.psf"); |
| 70 | + path p2("cygA.model"); |
| 71 | + path p3("cygA.image"); |
| 72 | + bool ans = exists(p1) && exists(p2) && exists(p3); |
| 73 | + |
| 74 | + EXPECT_TRUE( ans ); |
| 75 | + |
| 76 | + PagedImage<casacore::Float> psfimage("cygA.model"); |
| 77 | + float tol = 0.1; |
| 78 | + float goldValLoc0 = 0.095916; |
| 79 | + float goldValLoc1 = 0.0876324; |
| 80 | + |
| 81 | + EXPECT_NEAR(psfimage(IPosition(4,2937,2352,0,0)), goldValLoc0, tol); |
| 82 | + EXPECT_NEAR(psfimage(IPosition(4,1076,1785,0,0)), goldValLoc1, tol); |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + //move to parent directory |
| 87 | + std::filesystem::current_path(testDir.parent_path()); |
| 88 | + |
| 89 | + remove_all(testDir); |
| 90 | +} |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | +}; |
0 commit comments