From ac6c8d9c16941b116ead0dd2da79d2c2986b8fa6 Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Thu, 19 Sep 2024 14:51:22 +0200 Subject: [PATCH 1/9] Initial code Signed-off-by: Martin Zeithaml --- build/build_cmgr_xlclang.sh | 6 ++ tests/quickJS/README.md | 28 ++++++++ tests/quickJS/lib/print.js | 14 ++++ tests/quickJS/quickJS.js | 47 +++++++++++++ tests/quickJS/run_test.sh | 37 +++++++++++ tests/quickJS/testLib/testZos.js | 110 +++++++++++++++++++++++++++++++ 6 files changed, 242 insertions(+) create mode 100644 tests/quickJS/README.md create mode 100644 tests/quickJS/lib/print.js create mode 100644 tests/quickJS/quickJS.js create mode 100644 tests/quickJS/run_test.sh create mode 100644 tests/quickJS/testLib/testZos.js diff --git a/build/build_cmgr_xlclang.sh b/build/build_cmgr_xlclang.sh index b78293f3f..fd7f1a6af 100755 --- a/build/build_cmgr_xlclang.sh +++ b/build/build_cmgr_xlclang.sh @@ -166,6 +166,12 @@ xlclang \ rm -rf "${TMP_DIR}" +if [ "${1}" = "--test" ]; then + if [ -f "${COMMON}/bin/configmgr" ]; then + "${COMMON}/bin/configmgr" -script "${COMMON}/tests/quickJS/quickJS.js" + echo + fi +fi # This program and the accompanying materials are # made available under the terms of the Eclipse Public License v2.0 which accompanies diff --git a/tests/quickJS/README.md b/tests/quickJS/README.md new file mode 100644 index 000000000..e71692d0e --- /dev/null +++ b/tests/quickJS/README.md @@ -0,0 +1,28 @@ +# QuickJS tests + +## Simple unit tests + +This framework is as unit testing for individual javascript functions. + +## Adding new test + +Follow the existing structure, always returning the number of errors and tests. + +Keep in mind, test the simple cases like: +* Working cases +* No parameters when exepecting some +* Incorrect data types +* Empty, null, undefined values... + +```javascript +export function test_someFunction() { + const TEST = [ -1, 0, 1, 42 ] + let errs = 0; + for (let t in TEST) { + someFunction(TEST[t]); + ... + } + return { errors: errs, total: TEST.lenght } +} + +``` \ No newline at end of file diff --git a/tests/quickJS/lib/print.js b/tests/quickJS/lib/print.js new file mode 100644 index 000000000..38d39871e --- /dev/null +++ b/tests/quickJS/lib/print.js @@ -0,0 +1,14 @@ +/* +// 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. +*/ + +export function clog(condition, msg) { + console.log(`${condition ? '' : '== ERROR ==> '}${msg}`); +} diff --git a/tests/quickJS/quickJS.js b/tests/quickJS/quickJS.js new file mode 100644 index 000000000..39a64ebd3 --- /dev/null +++ b/tests/quickJS/quickJS.js @@ -0,0 +1,47 @@ +/* +// 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. +*/ + +import * as std from 'cm_std'; +import * as testZos from './testLib/testZos'; + +const TEST_ZOS = [ + testZos.test_changeTag, + testZos.test_changeExtAttr, + testZos.test_changeStreamCCSID, + testZos.test_zstat, + testZos.test_getZosVersion, + testZos.test_getEsm, + testZos.test_dslist, + testZos.test_resolveSymbol, + testZos.test_getStatvfs, +] + +const TESTS = [ + ...TEST_ZOS +] + +let result = {}; +let errors = 0; +let total = 0; + +for (let testFunction in TESTS) { + result = TESTS[testFunction](); + errors += result.errors; + total += result.total; +} + +if (errors) { + console.log(`\n${errors} error${errors == 1 ? '' : 's'} detected in ${total} tests, review the test output.\n`); + std.exit(8); +} else { + console.log(`\n${total} tests succesfull.\n`); + std.exit(0); +} diff --git a/tests/quickJS/run_test.sh b/tests/quickJS/run_test.sh new file mode 100644 index 000000000..5c87496b5 --- /dev/null +++ b/tests/quickJS/run_test.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +####################################################################### +# 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. +####################################################################### + +if [ `uname` != "OS/390" ]; then + echo "This test must run on a z/OS system." + exit 1 +fi + +if [ "${1}" = "--help" ]; then + echo "Run the Quick JS tests" + echo " no parm: tries to run configmgr from current 'zowe-common-c/bin'" + echo " path: path to configmgr" + echo " --help: this help" + exit 0 +fi + +configmgr_path="${1}" +if [ -z "${configmgr_path}" ]; then + configmgr_path="../../bin/configmgr" +fi + +if [ -f "${configmgr_path}" ]; then + "${configmgr_path}" -script ./quickJS.js +else + echo "configmgr not found in '${configmgr_path}'" + exit 4 +fi diff --git a/tests/quickJS/testLib/testZos.js b/tests/quickJS/testLib/testZos.js new file mode 100644 index 000000000..be004687b --- /dev/null +++ b/tests/quickJS/testLib/testZos.js @@ -0,0 +1,110 @@ +/* +// 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. +*/ + +import * as zos from 'zos'; +import * as print from '../lib/print'; + + +export function test_changeTag() { + return { errors: 0, total: 0 } +} + + +export function test_changeExtAttr() { + return { errors: 0, total: 0 } +} + + +export function test_changeStreamCCSID() { + return { errors: 0, total: 0 } +} + + +export function test_zstat() { + return { errors: 0, total: 0 } +} + + +export function test_getZosVersion() { + const result = zos.getZosVersion(); + print.clog(true, `zos.getZosVersion()=${result}${result > 0 ? ` --hex--> 0x${result.toString(16)}` : ``}`); + return { errors: result ? 0 : 1, total : 1 }; +} + + +export function test_getEsm() { + const EXPECTED = [ 'ACF2', 'RACF', 'TSS', 'NONE' ]; + const result = zos.getEsm(); + + if (result == null || !EXPECTED.includes(result)) { + print.clog(false, `zos.getEsms()=${result}`); + return { errors: 1, total: 1 }; + } + print.clog(true, `zos.getEsms()=${result}`); + return { errors: 0, total: 1 }; +} + + + +export function test_dslist() { + return { errors: 0, total: 0 } +} + + +export function test_resolveSymbol() { + const result = zos.resolveSymbol('&YYMMDD'); + const date = new Date(); + const yymmdd = (date.getFullYear() - 2000) * 10000 + (date.getMonth() + 1) * 100 + date.getDate() + ''; + let errs = 0; + + print.clog(result == yymmdd, `zos.resolveSymbol('&YYMMDD')=${result} -> ${yymmdd}`); + if (result != yymmdd) { + errs ++ + } + + const SYMBOLS_ERR = [ undefined, null, '', 'YYMMDD', ' &', ['a', 'b'], '& UNDEFINED SYMBOL !@#$%^&*()' ]; + for (let s in SYMBOLS_ERR) { + const result = zos.resolveSymbol(SYMBOLS_ERR[s]); + print.clog(result.length == 0, `zos.resolveSymbol(${SYMBOLS_ERR[s]})=${result}`); + if (result.length) { + errs++ + } + } + + return { errors: errs, total : SYMBOLS_ERR.length + 1 };; +} + + +export function test_getStatvfs() { + const PATHS_OK = [ './', '/', '/bin/' ]; + const PATHS_ERR = [ '', '/aaaaaaaaaaaaaaaaaaaaaaaaaaaaa', [ 'a', 3.14 ], { path: '/dev/null' }, null, true, false, undefined, 0, -1, 800 ]; + let errs = 0; + + for (let p in PATHS_OK) { + const result = zos.getStatvfs(PATHS_OK[p]); + print.clog(result[1] == 0, `zos.getStatvfs(${PATHS_OK[p]})=${result[1]}`); + if (result[1] != 0) { + errs++; + } + if (result[0]) { + console.log(` stats=${JSON.stringify(result[0])}`); + } + } + + for (let p in PATHS_ERR) { + const result = zos.getStatvfs(PATHS_ERR[p]); + print.clog(result[1] != 0, `zos.getStatvfs(${PATHS_ERR[p]})=${result[1]}`); + if (result[1] == 0) { + errs++; + } + } + return { errors: errs, total: PATHS_ERR.length + PATHS_OK.length }; +} From 5e422f88172fe2b6385b9b9f40f2257e48007ae3 Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Thu, 19 Sep 2024 14:57:46 +0200 Subject: [PATCH 2/9] Chmod for shell script Signed-off-by: Martin Zeithaml --- tests/quickJS/README.md | 0 tests/quickJS/run_test.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 tests/quickJS/README.md mode change 100644 => 100755 tests/quickJS/run_test.sh diff --git a/tests/quickJS/README.md b/tests/quickJS/README.md old mode 100644 new mode 100755 diff --git a/tests/quickJS/run_test.sh b/tests/quickJS/run_test.sh old mode 100644 new mode 100755 From 07be5fbe9f85dfdc2b4e9b9268f22048e596e82d Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Thu, 19 Sep 2024 15:01:42 +0200 Subject: [PATCH 3/9] Small readme update Signed-off-by: Martin Zeithaml --- tests/quickJS/README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) mode change 100755 => 100644 tests/quickJS/README.md diff --git a/tests/quickJS/README.md b/tests/quickJS/README.md old mode 100755 new mode 100644 index e71692d0e..70818ff28 --- a/tests/quickJS/README.md +++ b/tests/quickJS/README.md @@ -19,8 +19,11 @@ export function test_someFunction() { const TEST = [ -1, 0, 1, 42 ] let errs = 0; for (let t in TEST) { - someFunction(TEST[t]); - ... + const result = someFunction(TEST[t]); + print.clog(result == TEST[t], `someFunction(${TEST[i]})=${result}`); + if (result != TEST[t]) { + errs++; + } } return { errors: errs, total: TEST.lenght } } From 0cccad5e8c9e9fc96af772bed8dbfb83cf85f989 Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Tue, 24 Sep 2024 14:46:50 +0200 Subject: [PATCH 4/9] Dummy functions Signed-off-by: Martin Zeithaml --- tests/quickJS/lib/print.js | 41 ++++++++++++++++++++++++++++++-- tests/quickJS/quickJS.js | 5 ++-- tests/quickJS/testLib/testZos.js | 31 +++++++++++++++++------- 3 files changed, 64 insertions(+), 13 deletions(-) diff --git a/tests/quickJS/lib/print.js b/tests/quickJS/lib/print.js index 38d39871e..72c38703f 100644 --- a/tests/quickJS/lib/print.js +++ b/tests/quickJS/lib/print.js @@ -9,6 +9,43 @@ // Copyright Contributors to the Zowe Project. */ -export function clog(condition, msg) { - console.log(`${condition ? '' : '== ERROR ==> '}${msg}`); +export const RED = "\u001b[31m"; +export const GREEN = "\u001b[32m"; +export const YELLOW = "\u001b[33m"; +export const PURPLE = "\u001b[35m"; +export const CYAN = "\u001b[36m"; +export const RESET = "\u001b[0m"; + +export function color(color, msg) { + console.log(`${color}${msg}${RESET}`); +} + +export function red(msg) { + color(RED, msg); +} + +export function green(msg) { + color(GREEN, msg); +} + +export function yellow(msg) { + color(YELLOW, msg); +} + +export function purple(msg) { + color(PURPLE, msg); +} + +export function cyan(msg) { + color(CYAN, msg); +} + +export function conditionally(condition, ...msg) { + console.log(`${condition ? GREEN : RED}` + msg + RESET); +} + +export function lines(clr, msg) { + color(clr, `\n${'-'.repeat(msg.length)}`); + color(clr, `${msg}`); + color(clr, `${'-'.repeat(msg.length)}\n`); } diff --git a/tests/quickJS/quickJS.js b/tests/quickJS/quickJS.js index 39a64ebd3..aa936ecd6 100644 --- a/tests/quickJS/quickJS.js +++ b/tests/quickJS/quickJS.js @@ -10,6 +10,7 @@ */ import * as std from 'cm_std'; +import * as print from './lib/print'; import * as testZos from './testLib/testZos'; const TEST_ZOS = [ @@ -39,9 +40,9 @@ for (let testFunction in TESTS) { } if (errors) { - console.log(`\n${errors} error${errors == 1 ? '' : 's'} detected in ${total} tests, review the test output.\n`); + print.lines(print.RED, `${errors} error${errors == 1 ? '' : 's'} detected in ${total} tests, review the test output.`); std.exit(8); } else { - console.log(`\n${total} tests succesfull.\n`); + print.lines(print.GREEN, `${total} tests succesfull.`); std.exit(0); } diff --git a/tests/quickJS/testLib/testZos.js b/tests/quickJS/testLib/testZos.js index be004687b..f9ace809d 100644 --- a/tests/quickJS/testLib/testZos.js +++ b/tests/quickJS/testLib/testZos.js @@ -13,29 +13,41 @@ import * as zos from 'zos'; import * as print from '../lib/print'; +// int status = tagFile(pathname, ccsid); export function test_changeTag() { + const result = zos.changeTag('./'); + print.purple(`DUMMY TEST: zos.changeTag(./)=${result}`); return { errors: 0, total: 0 } } +// int status = changeExtendedAttributes(pathname, extattr, onOffInt ? true : false); export function test_changeExtAttr() { + const result = zos.changeExtAttr('./'); + print.purple(`DUMMY TEST: zos.changeExtAttr(./)=${result}`); return { errors: 0, total: 0 } } +// int status = convertOpenStream(fd, ccsid); export function test_changeStreamCCSID() { + const result = zos.changeStreamCCSID('./'); + print.purple(`DUMMY TEST: zos.changeStreamCCSID(./)=${result}`); return { errors: 0, total: 0 } } +// res = stat(pathNative, &st); export function test_zstat() { + const result = zos.zstat('./testLib/testZos.js'); + print.purple(`DUMMY TEST: zos.zstat(./testLib/testZos.js)=${JSON.stringify(result)}`); return { errors: 0, total: 0 } } export function test_getZosVersion() { const result = zos.getZosVersion(); - print.clog(true, `zos.getZosVersion()=${result}${result > 0 ? ` --hex--> 0x${result.toString(16)}` : ``}`); + print.conditionally(true, `zos.getZosVersion()=${result}${result > 0 ? `=hex(0x${result.toString(16)}` : ``})`); return { errors: result ? 0 : 1, total : 1 }; } @@ -45,16 +57,18 @@ export function test_getEsm() { const result = zos.getEsm(); if (result == null || !EXPECTED.includes(result)) { - print.clog(false, `zos.getEsms()=${result}`); + print.conditionally(false, `zos.getEsms()=${result}`); return { errors: 1, total: 1 }; } - print.clog(true, `zos.getEsms()=${result}`); + print.conditionally(true, `zos.getEsms()=${result}`); return { errors: 0, total: 1 }; } export function test_dslist() { + const result = zos.dslist('SYS1.MACLIB'); + print.purple(`DUMMY TEST: zos.zstat(SYS1.MACLIB)=${JSON.stringify(result)}`); return { errors: 0, total: 0 } } @@ -65,7 +79,7 @@ export function test_resolveSymbol() { const yymmdd = (date.getFullYear() - 2000) * 10000 + (date.getMonth() + 1) * 100 + date.getDate() + ''; let errs = 0; - print.clog(result == yymmdd, `zos.resolveSymbol('&YYMMDD')=${result} -> ${yymmdd}`); + print.conditionally(result == yymmdd, `zos.resolveSymbol('&YYMMDD')=${result} -> ${yymmdd}`); if (result != yymmdd) { errs ++ } @@ -73,12 +87,11 @@ export function test_resolveSymbol() { const SYMBOLS_ERR = [ undefined, null, '', 'YYMMDD', ' &', ['a', 'b'], '& UNDEFINED SYMBOL !@#$%^&*()' ]; for (let s in SYMBOLS_ERR) { const result = zos.resolveSymbol(SYMBOLS_ERR[s]); - print.clog(result.length == 0, `zos.resolveSymbol(${SYMBOLS_ERR[s]})=${result}`); + print.conditionally(result.length == 0, `zos.resolveSymbol(${SYMBOLS_ERR[s]})=${result}`); if (result.length) { errs++ } } - return { errors: errs, total : SYMBOLS_ERR.length + 1 };; } @@ -90,18 +103,18 @@ export function test_getStatvfs() { for (let p in PATHS_OK) { const result = zos.getStatvfs(PATHS_OK[p]); - print.clog(result[1] == 0, `zos.getStatvfs(${PATHS_OK[p]})=${result[1]}`); + print.conditionally(result[1] == 0, `zos.getStatvfs(${PATHS_OK[p]})=${result[1]}`); if (result[1] != 0) { errs++; } if (result[0]) { - console.log(` stats=${JSON.stringify(result[0])}`); + console.log(`Stats=${JSON.stringify(result[0])}`); } } for (let p in PATHS_ERR) { const result = zos.getStatvfs(PATHS_ERR[p]); - print.clog(result[1] != 0, `zos.getStatvfs(${PATHS_ERR[p]})=${result[1]}`); + print.conditionally(result[1] != 0, `zos.getStatvfs(${PATHS_ERR[p]})=${result[1]}`); if (result[1] == 0) { errs++; } From 1fa6dd23beaae29da21539c9a3ce4216119c5c15 Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Fri, 27 Sep 2024 17:18:27 +0200 Subject: [PATCH 5/9] More tests Signed-off-by: Martin Zeithaml --- tests/quickJS/README.md | 16 ------ tests/quickJS/lib/print.js | 16 +++++- tests/quickJS/lib/test.js | 37 +++++++++++++ tests/quickJS/quickJS.js | 27 +++------- tests/quickJS/testLib/hello.txt | 1 + tests/quickJS/testLib/testZos.js | 92 ++++++++++++++++++-------------- tests/quickJS/testSet.js | 28 ++++++++++ 7 files changed, 140 insertions(+), 77 deletions(-) create mode 100644 tests/quickJS/lib/test.js create mode 100644 tests/quickJS/testLib/hello.txt create mode 100644 tests/quickJS/testSet.js diff --git a/tests/quickJS/README.md b/tests/quickJS/README.md index 70818ff28..5c7675e2a 100644 --- a/tests/quickJS/README.md +++ b/tests/quickJS/README.md @@ -13,19 +13,3 @@ Keep in mind, test the simple cases like: * No parameters when exepecting some * Incorrect data types * Empty, null, undefined values... - -```javascript -export function test_someFunction() { - const TEST = [ -1, 0, 1, 42 ] - let errs = 0; - for (let t in TEST) { - const result = someFunction(TEST[t]); - print.clog(result == TEST[t], `someFunction(${TEST[i]})=${result}`); - if (result != TEST[t]) { - errs++; - } - } - return { errors: errs, total: TEST.lenght } -} - -``` \ No newline at end of file diff --git a/tests/quickJS/lib/print.js b/tests/quickJS/lib/print.js index 72c38703f..fcc6cdc87 100644 --- a/tests/quickJS/lib/print.js +++ b/tests/quickJS/lib/print.js @@ -40,8 +40,20 @@ export function cyan(msg) { color(CYAN, msg); } -export function conditionally(condition, ...msg) { - console.log(`${condition ? GREEN : RED}` + msg + RESET); +export function conditionally(condition, functionTested, parm, result, additionalInfo) { + if (typeof parm == 'object') { + parm = JSON.stringify(parm); + } + if (typeof result == 'object') { + result = JSON.stringify(result); + } + if (!additionalInfo) { + additionalInfo = ''; + } else { + additionalInfo = `[${additionalInfo}]`; + } + console.log(`${condition ? GREEN : RED}` + `${functionTested}("${parm}")=${result} ${additionalInfo}` + RESET); + return + !condition; } export function lines(clr, msg) { diff --git a/tests/quickJS/lib/test.js b/tests/quickJS/lib/test.js new file mode 100644 index 000000000..eae2e524f --- /dev/null +++ b/tests/quickJS/lib/test.js @@ -0,0 +1,37 @@ +/* +// 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. +*/ + +import * as print from './print'; + +export const CLASSIC_FAILS = [ '', null, undefined, true, false, -16, 0, 256, 3.141592, 999999999, + ['banana', 'apple', 'kiwi'], + { success: "guaranteed" } +]; + +export function process(testFunction, testSet, compare, msg) { + let errors = 0; + let result; + if (typeof compare == 'object') { + compare = JSON.stringify(compare); + } + for (let t in testSet) { + if (Array.isArray(testSet[t])) { + result = testFunction(...testSet[t]); + } else { + result = testFunction(testSet[t]); + } + if (typeof result == 'object') { + result = JSON.stringify(result); + } + errors += print.conditionally(result == compare, msg, testSet[t], result); + } + return errors; +} diff --git a/tests/quickJS/quickJS.js b/tests/quickJS/quickJS.js index aa936ecd6..248503208 100644 --- a/tests/quickJS/quickJS.js +++ b/tests/quickJS/quickJS.js @@ -11,33 +11,22 @@ import * as std from 'cm_std'; import * as print from './lib/print'; -import * as testZos from './testLib/testZos'; - -const TEST_ZOS = [ - testZos.test_changeTag, - testZos.test_changeExtAttr, - testZos.test_changeStreamCCSID, - testZos.test_zstat, - testZos.test_getZosVersion, - testZos.test_getEsm, - testZos.test_dslist, - testZos.test_resolveSymbol, - testZos.test_getStatvfs, -] - -const TESTS = [ - ...TEST_ZOS -] +import * as testSet from './testSet'; let result = {}; let errors = 0; let total = 0; -for (let testFunction in TESTS) { - result = TESTS[testFunction](); +const loopStart = Date.now(); +for (let testFunction in testSet.TESTS) { + result = testSet.TESTS[testFunction](); errors += result.errors; total += result.total; } +const loopEnd = Date.now(); + +const timeDiff = loopEnd-loopStart; +print.cyan(`\nTime elapsed ${timeDiff} ms.`); if (errors) { print.lines(print.RED, `${errors} error${errors == 1 ? '' : 's'} detected in ${total} tests, review the test output.`); diff --git a/tests/quickJS/testLib/hello.txt b/tests/quickJS/testLib/hello.txt new file mode 100644 index 000000000..22575620a --- /dev/null +++ b/tests/quickJS/testLib/hello.txt @@ -0,0 +1 @@ +çÁ%%?Œ€Ï?Ê%ÀŽ \ No newline at end of file diff --git a/tests/quickJS/testLib/testZos.js b/tests/quickJS/testLib/testZos.js index f9ace809d..4fadefdf0 100644 --- a/tests/quickJS/testLib/testZos.js +++ b/tests/quickJS/testLib/testZos.js @@ -9,15 +9,30 @@ // Copyright Contributors to the Zowe Project. */ +// ======================== +// zowe-common-c/c/qjszos.c +// ======================== + import * as zos from 'zos'; import * as print from '../lib/print'; +import * as test from '../lib/test'; -// int status = tagFile(pathname, ccsid); export function test_changeTag() { - const result = zos.changeTag('./'); - print.purple(`DUMMY TEST: zos.changeTag(./)=${result}`); - return { errors: 0, total: 0 } + let errs; + const FAILS = [ ...test.CLASSIC_FAILS, + './file, which does not exit', ['./file, which does not exit', 250000 ], + ] + const FINES = [ + [ './testLib/hello.txt', 0 ], + [ './testLib/hello.txt', 859 ], + [ './testLib/hello.txt', 1047 ], + ]; + + errs = test.process(zos.changeTag, FAILS, -1, 'zos.changeTag'); + errs += test.process(zos.changeTag, FINES, 0, 'zos.changeTag'); + + return { errors: errs, total: FAILS.length + FINES.length } } @@ -37,17 +52,25 @@ export function test_changeStreamCCSID() { } -// res = stat(pathNative, &st); export function test_zstat() { - const result = zos.zstat('./testLib/testZos.js'); - print.purple(`DUMMY TEST: zos.zstat(./testLib/testZos.js)=${JSON.stringify(result)}`); - return { errors: 0, total: 0 } + const FAILS = [ ...test.CLASSIC_FAILS ]; + const FINES = [ './testLib/hello.txt', './', './run_test.sh' ]; + let errs = 0; + for (let f in FAILS) { + const result = zos.zstat(FAILS[f]); + errs += print.conditionally(result[1] == 129, 'zos.zstat', FAILS[f], result); + } + for (let f in FINES) { + const result = zos.zstat(FINES[f]); + errs += print.conditionally(result[1] == 0, 'zos.zstat', FINES[f], result); + } + return { errors: errs, total: FAILS.length } } export function test_getZosVersion() { const result = zos.getZosVersion(); - print.conditionally(true, `zos.getZosVersion()=${result}${result > 0 ? `=hex(0x${result.toString(16)}` : ``})`); + print.conditionally(true, 'zos.getZosVersion', 'no parameter', result, `${result > 0 ? `in hex 0x${result.toString(16)}` : ``}`); return { errors: result ? 0 : 1, total : 1 }; } @@ -57,19 +80,24 @@ export function test_getEsm() { const result = zos.getEsm(); if (result == null || !EXPECTED.includes(result)) { - print.conditionally(false, `zos.getEsms()=${result}`); + print.conditionally(false, 'zos.getEsms', 'no parameter', result); return { errors: 1, total: 1 }; } - print.conditionally(true, `zos.getEsms()=${result}`); + print.conditionally(true, 'zos.getEsms', 'no parameter', result); return { errors: 0, total: 1 }; } - export function test_dslist() { - const result = zos.dslist('SYS1.MACLIB'); - print.purple(`DUMMY TEST: zos.zstat(SYS1.MACLIB)=${JSON.stringify(result)}`); - return { errors: 0, total: 0 } + const FAILS = [ ...test.CLASSIC_FAILS, 'sys1.maclib' ]; + const FINES = [ 'SYS1.PARMLIB', 'SYS1.MACLIB' ]; + + let errs = test.process(zos.dslist, FAILS, null, 'zos.dslist'); + for (let f in FINES) { + const result = zos.dslist(FINES[f]); + errs += print.conditionally(result.datasets[0].dsn == FINES[f], 'zos.dslist', FINES[f], result); + } + return { errors: errs, total: FAILS.length + FINES.length } } @@ -79,45 +107,29 @@ export function test_resolveSymbol() { const yymmdd = (date.getFullYear() - 2000) * 10000 + (date.getMonth() + 1) * 100 + date.getDate() + ''; let errs = 0; - print.conditionally(result == yymmdd, `zos.resolveSymbol('&YYMMDD')=${result} -> ${yymmdd}`); - if (result != yymmdd) { - errs ++ - } + errs += print.conditionally(result == yymmdd, 'zos.resolveSymbol', '&YYMMDD', result, `javascript date -> ${yymmdd}`); - const SYMBOLS_ERR = [ undefined, null, '', 'YYMMDD', ' &', ['a', 'b'], '& UNDEFINED SYMBOL !@#$%^&*()' ]; - for (let s in SYMBOLS_ERR) { - const result = zos.resolveSymbol(SYMBOLS_ERR[s]); - print.conditionally(result.length == 0, `zos.resolveSymbol(${SYMBOLS_ERR[s]})=${result}`); - if (result.length) { - errs++ - } - } - return { errors: errs, total : SYMBOLS_ERR.length + 1 };; + const ERR_SYMBOLS = [ ...test.CLASSIC_FAILS, 'YYMMDD', ' &', ['a', 'b'], '& UNDEFINED SYMBOL !@#$%^&*()' ]; + errs += test.process(zos.resolveSymbol, ERR_SYMBOLS, '', 'zos.resolveSymbol'); + + return { errors: errs, total : ERR_SYMBOLS.length + 1 };; } export function test_getStatvfs() { const PATHS_OK = [ './', '/', '/bin/' ]; - const PATHS_ERR = [ '', '/aaaaaaaaaaaaaaaaaaaaaaaaaaaaa', [ 'a', 3.14 ], { path: '/dev/null' }, null, true, false, undefined, 0, -1, 800 ]; + const PATHS_ERR = [ ...test.CLASSIC_FAILS, '/aaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbb/ccccccccccccccccccccccc' ]; let errs = 0; for (let p in PATHS_OK) { const result = zos.getStatvfs(PATHS_OK[p]); - print.conditionally(result[1] == 0, `zos.getStatvfs(${PATHS_OK[p]})=${result[1]}`); - if (result[1] != 0) { - errs++; - } - if (result[0]) { - console.log(`Stats=${JSON.stringify(result[0])}`); - } + errs += print.conditionally(result[1] == 0, 'zos.getStatvfs', PATHS_OK[p], result); } for (let p in PATHS_ERR) { const result = zos.getStatvfs(PATHS_ERR[p]); - print.conditionally(result[1] != 0, `zos.getStatvfs(${PATHS_ERR[p]})=${result[1]}`); - if (result[1] == 0) { - errs++; - } + errs += print.conditionally(result[1] != 0, 'zos.getStatvfs', PATHS_ERR[p], result[1]); } + return { errors: errs, total: PATHS_ERR.length + PATHS_OK.length }; } diff --git a/tests/quickJS/testSet.js b/tests/quickJS/testSet.js new file mode 100644 index 000000000..00f02e25a --- /dev/null +++ b/tests/quickJS/testSet.js @@ -0,0 +1,28 @@ +/* +// 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. +*/ + +import * as testZos from './testLib/testZos' + +export const TEST_ZOS = [ + testZos.test_changeTag, + testZos.test_changeExtAttr, + testZos.test_changeStreamCCSID, + testZos.test_zstat, + testZos.test_getZosVersion, + testZos.test_getEsm, + testZos.test_dslist, + testZos.test_resolveSymbol, + testZos.test_getStatvfs, +]; + +export const TESTS = [ + ...TEST_ZOS +]; \ No newline at end of file From e5d72d76aecbac0bf11dc944f0c2ac98266914d8 Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Tue, 8 Oct 2024 14:35:47 +0200 Subject: [PATCH 6/9] Build update Signed-off-by: Martin Zeithaml --- build/build_cmgr_xlclang.sh | 4 +++- tests/quickJS/run_test.sh | 4 ++-- tests/quickJS/testLib/testZos.js | 22 ++++++++++++---------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/build/build_cmgr_xlclang.sh b/build/build_cmgr_xlclang.sh index fd7f1a6af..8f597573e 100755 --- a/build/build_cmgr_xlclang.sh +++ b/build/build_cmgr_xlclang.sh @@ -168,7 +168,9 @@ rm -rf "${TMP_DIR}" if [ "${1}" = "--test" ]; then if [ -f "${COMMON}/bin/configmgr" ]; then - "${COMMON}/bin/configmgr" -script "${COMMON}/tests/quickJS/quickJS.js" + cd "${COMMON}/tests/quickJS/" + ./run_test.sh + cd "${WORKING_DIR}" echo fi fi diff --git a/tests/quickJS/run_test.sh b/tests/quickJS/run_test.sh index 5c87496b5..14d7d28f6 100755 --- a/tests/quickJS/run_test.sh +++ b/tests/quickJS/run_test.sh @@ -12,7 +12,7 @@ ####################################################################### if [ `uname` != "OS/390" ]; then - echo "This test must run on a z/OS system." + echo "Error: this test must run on a z/OS system." exit 1 fi @@ -32,6 +32,6 @@ fi if [ -f "${configmgr_path}" ]; then "${configmgr_path}" -script ./quickJS.js else - echo "configmgr not found in '${configmgr_path}'" + echo "Error: configmgr not found in '${configmgr_path}'" exit 4 fi diff --git a/tests/quickJS/testLib/testZos.js b/tests/quickJS/testLib/testZos.js index 4fadefdf0..66d4815da 100644 --- a/tests/quickJS/testLib/testZos.js +++ b/tests/quickJS/testLib/testZos.js @@ -20,7 +20,7 @@ import * as test from '../lib/test'; export function test_changeTag() { let errs; - const FAILS = [ ...test.CLASSIC_FAILS, + const FAILS = [ ...test.CLASSIC_FAILS, './file, which does not exit', ['./file, which does not exit', 250000 ], ] const FINES = [ @@ -36,19 +36,21 @@ export function test_changeTag() { } -// int status = changeExtendedAttributes(pathname, extattr, onOffInt ? true : false); export function test_changeExtAttr() { - const result = zos.changeExtAttr('./'); - print.purple(`DUMMY TEST: zos.changeExtAttr(./)=${result}`); - return { errors: 0, total: 0 } + const FINES = [ + ['./testLib/hello.txt', zos.EXTATTR_PROGCTL, true ], + ['./testLib/hello.txt', zos.EXTATTR_PROGCTL, false ], + ] + let errs = test.process(zos.changeExtAttr, test.CLASSIC_FAILS, -1, 'zos.changeExtAttr'); + errs += test.process(zos.changeExtAttr, FINES, 0, 'zos.changeExtAttr'); + return { errors: errs, total: test.CLASSIC_FAILS.length + FINES.length } } -// int status = convertOpenStream(fd, ccsid); export function test_changeStreamCCSID() { - const result = zos.changeStreamCCSID('./'); - print.purple(`DUMMY TEST: zos.changeStreamCCSID(./)=${result}`); - return { errors: 0, total: 0 } + const FAILS = [ -2, -1, 999999999, 1024*1024 ]; + const errs = test.process(zos.changeStreamCCSID, FAILS, -1, 'zos.changeStreamCCSID'); + return { errors: errs, total: FAILS.length } } @@ -64,7 +66,7 @@ export function test_zstat() { const result = zos.zstat(FINES[f]); errs += print.conditionally(result[1] == 0, 'zos.zstat', FINES[f], result); } - return { errors: errs, total: FAILS.length } + return { errors: errs, total: FAILS.length + FINES.length } } From 11779dccc1ec5586e8ab062ea9134ed9f2cf4c8d Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Tue, 8 Oct 2024 14:38:00 +0200 Subject: [PATCH 7/9] Hello update Signed-off-by: Martin Zeithaml --- tests/quickJS/testLib/hello.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/quickJS/testLib/hello.txt b/tests/quickJS/testLib/hello.txt index 22575620a..5dd01c177 100644 --- a/tests/quickJS/testLib/hello.txt +++ b/tests/quickJS/testLib/hello.txt @@ -1 +1 @@ -çÁ%%?Œ€Ï?Ê%ÀŽ \ No newline at end of file +Hello, world! \ No newline at end of file From 481bf7a07d5b7de8a7ac2722f85ad6523390265c Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Tue, 8 Oct 2024 14:40:16 +0200 Subject: [PATCH 8/9] Added new line Signed-off-by: Martin Zeithaml --- tests/quickJS/testSet.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/quickJS/testSet.js b/tests/quickJS/testSet.js index 00f02e25a..b58140610 100644 --- a/tests/quickJS/testSet.js +++ b/tests/quickJS/testSet.js @@ -25,4 +25,4 @@ export const TEST_ZOS = [ export const TESTS = [ ...TEST_ZOS -]; \ No newline at end of file +]; From a54da696c665bb633d6f79dd2fbb0e914a97466f Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Wed, 9 Oct 2024 10:18:15 +0200 Subject: [PATCH 9/9] Move testSet to lib Signed-off-by: Martin Zeithaml --- tests/quickJS/{ => lib}/testSet.js | 2 +- tests/quickJS/quickJS.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename tests/quickJS/{ => lib}/testSet.js (93%) diff --git a/tests/quickJS/testSet.js b/tests/quickJS/lib/testSet.js similarity index 93% rename from tests/quickJS/testSet.js rename to tests/quickJS/lib/testSet.js index b58140610..471563041 100644 --- a/tests/quickJS/testSet.js +++ b/tests/quickJS/lib/testSet.js @@ -9,7 +9,7 @@ // Copyright Contributors to the Zowe Project. */ -import * as testZos from './testLib/testZos' +import * as testZos from '../testLib/testZos' export const TEST_ZOS = [ testZos.test_changeTag, diff --git a/tests/quickJS/quickJS.js b/tests/quickJS/quickJS.js index 248503208..0e51d224d 100644 --- a/tests/quickJS/quickJS.js +++ b/tests/quickJS/quickJS.js @@ -11,7 +11,7 @@ import * as std from 'cm_std'; import * as print from './lib/print'; -import * as testSet from './testSet'; +import * as testSet from './lib/testSet'; let result = {}; let errors = 0;