Skip to content
Draft
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions native/c/test/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ build-out/zmetal.test.o \
build-out/zmetal.metal.test.o \
build-out/zusf.test.o \
build-out/zusf.o \
build-out/zowex.ds.test.o \
build-out/zowex.test.o \
build-out/parser.test.o \
build-out/zlogger.test.o \
Expand Down Expand Up @@ -232,6 +233,9 @@ build-out/zcnm31.o:
build-out/zusf.o:
ln -sf ../../build-out/xlclang/zusf.o build-out/zusf.o

build-out/zowex.ds.test.o: zowex.ds.test.cpp
$(OCXX) $(CXXLANG_FLAGS) -qlist=$*.cpp.lst -c $^ -o $@

build-out/zowex.test.o: zowex.test.cpp
$(OCXX) $(CXXLANG_FLAGS) -qlist=$*.cpp.lst -c $^ -o $@

Expand Down
362 changes: 201 additions & 161 deletions native/c/test/zds.test.cpp

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions native/c/test/zjb.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ void zjb_tests()
rc = zjb_read_job_jcl(&zjb, correlator, returned_jcl);

ExpectWithContext(rc, zjb.diag.e_msg).ToBe(RTNCD_SUCCESS); });


// https://github.com/zowe/zowe-native-proto/issues/641
it("should be able to list and view SYSOUT files for INPUT jobs", [&]() -> void
{
ZJB zjb = {0};
Expand Down Expand Up @@ -150,8 +151,7 @@ void zjb_tests()

memset(&zjb, 0, sizeof(zjb));
rc = zjb_delete(&zjb, correlator);
ExpectWithContext(rc, zjb.diag.e_msg).ToBe(RTNCD_SUCCESS); });
});
ExpectWithContext(rc, zjb.diag.e_msg).ToBe(RTNCD_SUCCESS); }); });
}

void sleep_on_status(string status, string jobid)
Expand Down
441 changes: 441 additions & 0 deletions native/c/test/zowex.ds.test.cpp

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions native/c/test/zowex.ds.test.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*
*/

#ifndef ZOWEX_DS_TEST_HPP
#define ZOWEX_DS_TEST_HPP
void zowex_ds_tests();
#endif
148 changes: 11 additions & 137 deletions native/c/test/zowex.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,56 +9,28 @@
*
*/

#include <cstddef>
#include <ctime>
#include <sstream>
#include <stdexcept>
#include <stdlib.h>
#include <string>
#include <vector>
#include "ztest.hpp"
#include "ztype.h"
#include "ztest.utils.hpp"
#include "zowex.test.hpp"
#include "zowex.ds.test.hpp"

using namespace std;
using namespace ztst;

// Helper function to convert string to hex format
// TODO(Kelosky): move to zut.hpp if additional use is found
string string_to_hex(const string &input)
{
string hex_output;
for (char c : input)
{
char hex_byte[3];
sprintf(hex_byte, "%02x", static_cast<unsigned char>(c));
hex_output += hex_byte;
}
return hex_output;
}

// NOTE(Kelosky): consolidate this into ztest.hpp if additional use is found
int execute_command_with_output(const std::string &command, std::string &output)
{
output = "";
// TestLog("Running: " + command);

FILE *pipe = popen((command + " 2>&1").c_str(), "r");
if (!pipe)
{
throw std::runtime_error("Failed to open pipe");
}

char buffer[256];
while (fgets(buffer, sizeof(buffer), pipe) != nullptr)
{
output += buffer;
}

int exit_code = pclose(pipe);
return WEXITSTATUS(exit_code);
}

const string zowex_command = "./../build-out/zowex";

void zowex_tests()
{

describe("zowex tests",
describe("zowex",
[]() -> void
{
it("should list a version of the tool",
Expand All @@ -79,7 +51,7 @@ void zowex_tests()
int file_size = stoi(response);
ExpectWithContext(file_size, response).ToBeLessThan(10 * 1024 * 1024);
});
describe("job tests",
describe("job",
[]() -> void
{
it("should list jobs",
Expand Down Expand Up @@ -128,104 +100,6 @@ void zowex_tests()
ExpectWithContext(rc, stderr_output).ToBe(0);
Expect(stdout_output).ToContain("deleted"); });
});
describe("data set tests",
[]() -> void
{
// describe("data set create tests",
// []() -> void
// {
// it("should create a fb data set",
// []()
// {
// int rc = 0;
// string user;
// execute_command_with_output("whoami", user);
// string data_set = TrimChars(user) + ".temp.temp.temp.temp.temp.temp.tmp";
// string response;
// string del_command = zowex_command + " data-set delete " + data_set;
// execute_command_with_output(del_command, response);
// string command = zowex_command + " data-set create-fb " + data_set;
// rc = execute_command_with_output(command, response);
// ExpectWithContext(rc, response).ToBe(0);
// execute_command_with_output(del_command, response);
// });
// });
describe("data set list tests",
[]() -> void
{
it("should list a data set",
[]()
{
int rc = 0;
string data_set = "SYS1.MACLIB";
string response;
string command = zowex_command + " data-set list " + data_set;
rc = execute_command_with_output(command, response);
ExpectWithContext(rc, response).ToBe(0);
});
it("should list a member of a data set",
[]()
{
string data_set = "SYS1.MACLIB";
string response;
string command = zowex_command + " data-set lm " + data_set + " --no-warn --me 1";
TestLog("Running: " + command);
int rc = execute_command_with_output(command, response);
ExpectWithContext(rc, response).ToBe(0);
});
it("should warn when listing members of a data set with many members",
[]()
{
int rc = 0;
string data_set = "SYS1.MACLIB";
string response;
string command = zowex_command + " data-set lm " + data_set + " --me 1";
rc = execute_command_with_output(command, response);
ExpectWithContext(rc, response).ToBe(RTNCD_WARNING);
});
});

// describe("data set i/o tests",
// []() -> void
// {
// it("should write and read from a data set",
// []()
// {
// int rc = 0;
// string user;
// execute_command_with_output("whoami", user);
// string data_set = TrimChars(user) + ".temp.temp.temp.temp.temp.temp.tmp";
// string member = "IEFBR14";
// string data_set_member = "\"" + data_set + "(" + member + ")\"";
// string response;

// // delete the data set if it exists
// string del_command = zowex_command + " data-set delete " + data_set;
// execute_command_with_output(del_command, response);

// // create the data set
// string command = zowex_command + " data-set create-fb " + data_set;
// rc = execute_command_with_output(command, response);
// ExpectWithContext(rc, response).ToBe(0);

// string jcl = "//IEFBR14$ JOB (IZUACCT),TEST,REGION=0M\n//RUN EXEC PGM=IEFBR14";

// // Convert JCL to hex format and write to the data set
// string hex_jcl = string_to_hex(jcl);
// string write_command = "printf \"" + hex_jcl + "\" | " + zowex_command + " data-set write " + data_set_member;
// rc = execute_command_with_output(write_command, response);
// ExpectWithContext(rc, response).ToBe(0);

// // read from the data set
// string read_command = zowex_command + " data-set view " + data_set_member;
// rc = execute_command_with_output(read_command, response);
// ExpectWithContext(rc, response).ToBe(0);
// Expect(TrimChars(response)).ToBe(jcl);

// // delete the data set
// execute_command_with_output(del_command, response);
// });
// });
});
zowex_ds_tests();
});
}
8 changes: 6 additions & 2 deletions native/c/test/ztest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,12 @@
}
void test_log(const std::string &message)
{
pad_nesting(get_nesting());
std::cout << "[TEST_INFO] " << message << std::endl;
const char *debug = getenv("ZNP_TEST_LOG");
if (debug == nullptr || strstr(debug, "ON") != nullptr)
{
pad_nesting(get_nesting());

Check warning

Code scanning / CodeQL

Expression has no effect Warning test

This expression has no effect (because
pad_nesting
has no external side effects).

Copilot Autofix

AI 1 day ago

The recommended fix for this issue, per static analysis guidance, is to explicitly cast the function call expression to void, using (void)pad_nesting(get_nesting());. This documents that it is executed for its side effect only, and clarifies to reviewers and tools that the function’s return value (void) is intentionally ignored. The only change required is to line 414 of native/c/test/ztest.hpp, within the body of test_log, replacing the plain call to pad_nesting(get_nesting()); with (void)pad_nesting(get_nesting());. No imports or other changes are necessary.

Suggested changeset 1
native/c/test/ztest.hpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/native/c/test/ztest.hpp b/native/c/test/ztest.hpp
--- a/native/c/test/ztest.hpp
+++ b/native/c/test/ztest.hpp
@@ -411,7 +411,7 @@
     const char *debug = getenv("ZNP_TEST_LOG");
     if (debug == nullptr || strstr(debug, "ON") != nullptr)
     {
-      pad_nesting(get_nesting());
+      (void)pad_nesting(get_nesting());
       std::cout << "[TEST_INFO] " << message << std::endl;
     }
   }
EOF
@@ -411,7 +411,7 @@
const char *debug = getenv("ZNP_TEST_LOG");
if (debug == nullptr || strstr(debug, "ON") != nullptr)
{
pad_nesting(get_nesting());
(void)pad_nesting(get_nesting());
std::cout << "[TEST_INFO] " << message << std::endl;
}
}
Copilot is powered by AI and may make mistakes. Always verify output.
std::cout << "[TEST_INFO] " << message << std::endl;
}
}

// Execute a vector of hooks, catching and reporting any errors
Expand Down
105 changes: 105 additions & 0 deletions native/c/test/ztest.utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*
*/

#ifndef ZTEST_UTILS_HPP
#define ZTEST_UTILS_HPP

#include "ztest.hpp"
#include <iostream>

using namespace std;

// Helper function to convert string to hex format
// TODO(Kelosky): move to zut.hpp if additional use is found
string string_to_hex(const string &input)
{
string hex_output;
for (char c : input)
{
char hex_byte[3];
sprintf(hex_byte, "%02x", static_cast<unsigned char>(c));
hex_output += hex_byte;
}
return hex_output;
}

// NOTE(Kelosky): consolidate this into ztest.hpp if additional use is found
int execute_command_with_output(const string &command, string &output)
{
output = "";
// TestLog("Running: " + command);

Check notice

Code scanning / CodeQL

Commented-out code Note test

This comment appears to contain commented-out code.

Copilot Autofix

AI 1 day ago

The best way to fix this problem is to remove the commented-out code, as retaining commented-out code leads to code rot and confusion. If the logging functionality is still desired or needed, the author should add a properly enabled logging statement, perhaps with a guard or modern logging mechanism. If it was left for future use or as a suggestion, it should be transformed into a regular code comment, not a commented-out code line.

For minimum intervention and to avoid changing behavior, the fix should be to delete line 38 entirely from native/c/test/ztest.utils.hpp. Only this line must be removed; no imports or other changes are necessary.

Suggested changeset 1
native/c/test/ztest.utils.hpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/native/c/test/ztest.utils.hpp b/native/c/test/ztest.utils.hpp
--- a/native/c/test/ztest.utils.hpp
+++ b/native/c/test/ztest.utils.hpp
@@ -35,7 +35,6 @@
 int execute_command_with_output(const string &command, string &output)
 {
   output = "";
-  // TestLog("Running: " + command);
 
   FILE *pipe = popen((command + " 2>&1").c_str(), "r");
   if (!pipe)
EOF
@@ -35,7 +35,6 @@
int execute_command_with_output(const string &command, string &output)
{
output = "";
// TestLog("Running: " + command);

FILE *pipe = popen((command + " 2>&1").c_str(), "r");
if (!pipe)
Copilot is powered by AI and may make mistakes. Always verify output.

FILE *pipe = popen((command + " 2>&1").c_str(), "r");
if (!pipe)
{
throw runtime_error("Failed to open pipe");
}

char buffer[256];
while (fgets(buffer, sizeof(buffer), pipe) != nullptr)
{
output += buffer;
}

int exit_code = pclose(pipe);
return WEXITSTATUS(exit_code);
}

string get_random_string(const int length = 7, const bool allNumbers = true)
{
static bool seeded = false;
if (!seeded)
{
srand(static_cast<unsigned int>(time(NULL)));
seeded = true;
}
string ret = "";
for (int i = 0; i < length; ++i)
{
ret += to_string(rand() % 10);
}
return ret;
}

string get_random_ds(const int qualifier_count = 4, const string hlq = "")
{
string q = hlq;
if (q.length() == 0)
{
string user;
execute_command_with_output("whoami", user);
q = ztst::TrimChars(user);
}
string ret = q + ".ZNP#TEST";
for (int i = 0; i < qualifier_count - 2; ++i)
{
ret += ".Z" + get_random_string();
}
return ret;
}

vector<string> split_rfc_response(const string input, const char *delim)
{
vector<string> ret;
char *cstr = new char[input.length() + 1];
strcpy(cstr, input.c_str());
char *token_ptr = strtok(cstr, delim);
while (token_ptr != NULL)
{
string token = token_ptr;
ret.push_back(ztst::TrimChars(token));
token_ptr = strtok(NULL, delim);
}
delete[] cstr;
return ret;
}

#endif
Loading