Skip to content

Commit c9f295e

Browse files
committed
alpine tests + CI
1 parent 602becc commit c9f295e

File tree

6 files changed

+108
-27
lines changed

6 files changed

+108
-27
lines changed

.gitlab-ci.yml

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,42 @@
11
stages:
22
- test
33

4-
test:
5-
stage: test
6-
image: $CI_REGISTRY/infrastructure/qore-test-base/qore-test-base:develop
4+
default:
75
tags:
86
- docker-exec
9-
variables:
10-
REPO_NAME: module-process
11-
script:
7+
before_script:
128
- |
139
curl "https://api.github.com/repos/qorelanguage/${REPO_NAME}/statuses/${CI_COMMIT_SHA}" \
1410
-X POST -u omusil24:${GITHUB_ACCESS_TOKEN} -H "Content-Type: application/json" \
1511
-d "{\"state\": \"pending\", \"context\": \"${REPO_NAME}\", \"description\": \"Gitlab CI\", \"target_url\": \"${CI_JOB_URL}\"}"
12+
- set +e
13+
14+
variables:
15+
REPO_NAME: module-process
16+
17+
test-ubuntu:
18+
stage: test
19+
image: $CI_REGISTRY/infrastructure/qore-test-base/qore-test-base:develop
20+
script:
21+
- |
22+
if test/docker_test/test-ubuntu.sh; then
23+
curl "https://api.github.com/repos/qorelanguage/${REPO_NAME}/statuses/${CI_COMMIT_SHA}" \
24+
-X POST -u omusil24:${GITHUB_ACCESS_TOKEN} -H "Content-Type: application/json" \
25+
-d "{\"state\": \"success\", \"context\": \"${REPO_NAME}\", \"description\": \"Gitlab CI\", \"target_url\": \"${CI_JOB_URL}\"}"
26+
exit 0
27+
else
28+
curl "https://api.github.com/repos/qorelanguage/${REPO_NAME}/statuses/${CI_COMMIT_SHA}" \
29+
-X POST -u omusil24:${GITHUB_ACCESS_TOKEN} -H "Content-Type: application/json" \
30+
-d "{\"state\": \"failure\", \"context\": \"${REPO_NAME}\", \"description\": \"Gitlab CI\", \"target_url\": \"${CI_JOB_URL}\"}"
31+
exit 1
32+
fi
33+
34+
test-alpine:
35+
stage: test
36+
image: $CI_REGISTRY/infrastructure/qore-test-base/qore-test-base:develop-alpine
37+
script:
1638
- |
17-
set +e
18-
if test/docker_test/test.sh; then
39+
if test/docker_test/test-alpine.sh; then
1940
curl "https://api.github.com/repos/qorelanguage/${REPO_NAME}/statuses/${CI_COMMIT_SHA}" \
2041
-X POST -u omusil24:${GITHUB_ACCESS_TOKEN} -H "Content-Type: application/json" \
2142
-d "{\"state\": \"success\", \"context\": \"${REPO_NAME}\", \"description\": \"Gitlab CI\", \"target_url\": \"${CI_JOB_URL}\"}"

src/QC_Process.qpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ p.wait(); # a blocking/wait call
325325
printf("Sleep finished with code: %d\n", p.exitCode());
326326
@endcode
327327

328-
@return always returns \c True to keep compatibility with wait(timeout) version
328+
@return \c True if child exited while waiting, otherwise return \c False
329329

330330
@throw PROCESS-CHECK-ERROR in case child handle was not properly initialized
331331

@@ -760,4 +760,4 @@ static list<float> Process::getLoadAvg() [flags=RET_VALUE_ONLY] {
760760
assert(!*xsink);
761761
}
762762
return rv.release();
763-
}
763+
}

src/processpriv.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -722,14 +722,17 @@ bool ProcessPriv::wait(ExceptionSink* xsink) {
722722
return false;
723723

724724
try {
725-
if (m_process->valid()) {
725+
if (m_process->valid() && m_process->running()) {
726726
m_process->wait();
727727

728728
// get exit code if possible
729729
getExitCode(xsink);
730730

731731
// rethrows any background exceptions
732732
finalizeStreams(xsink);
733+
} else {
734+
// invalidate the exit code since the return value of m_process->exit_code() is without any meaning now
735+
exit_code = 0;
733736
}
734737
return true;
735738
} catch (const std::exception& ex) {
@@ -766,20 +769,21 @@ bool ProcessPriv::wait(int64 t, ExceptionSink* xsink) {
766769

767770
return true;
768771
}
772+
} else {
773+
// invalidate the exit code since the return value of m_process->exit_code() is without any meaning now
774+
exit_code = 0;
769775
}
770776
return false;
771777
} catch (const std::exception& ex) {
772778
// ignore errors if the process has already terminated
773779
const char* err = ex.what();
774780
if (!strcmp("wait error: No child processes", err)) {
775781
// get exit code if possible
776-
try {
777-
exit_code = m_process->exit_code();
778-
} catch (const std::exception& ex) {
779-
xsink->raiseException("PROCESS-EXITCODE-ERROR", ex.what());
780-
}
782+
getExitCode(xsink);
783+
781784
// rethrows any background exceptions
782785
finalizeStreams(xsink);
786+
783787
return true;
784788
} else {
785789
xsink->raiseException("PROCESS-WAIT-ERROR", err);

test/docker_test/test-alpine.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
3+
set -e
4+
set -x
5+
6+
ENV_FILE=/tmp/env.sh
7+
8+
. ${ENV_FILE}
9+
10+
# setup MODULE_SRC_DIR env var
11+
cwd=`pwd`
12+
if [ -z "${MODULE_SRC_DIR}" ]; then
13+
if [ -e "$cwd/src/processpriv.cpp" ] || [ -e "$cwd/src/process.qpp" ]; then
14+
MODULE_SRC_DIR=$cwd
15+
else
16+
MODULE_SRC_DIR=$WORKDIR/module-process
17+
fi
18+
fi
19+
echo "export MODULE_SRC_DIR=${MODULE_SRC_DIR}" >> ${ENV_FILE}
20+
21+
echo "export QORE_UID=1000" >> ${ENV_FILE}
22+
echo "export QORE_GID=1000" >> ${ENV_FILE}
23+
24+
. ${ENV_FILE}
25+
26+
export MAKE_JOBS=4
27+
28+
# build module and install
29+
echo && echo "-- building module --"
30+
mkdir -p ${MODULE_SRC_DIR}/build
31+
cd ${MODULE_SRC_DIR}/build
32+
cmake .. -DCMAKE_BUILD_TYPE=debug -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX}
33+
make -j${MAKE_JOBS}
34+
make install
35+
36+
# add Qore user and group
37+
if ! grep -q "^qore:x:${QORE_GID}" /etc/group; then
38+
addgroup -g ${QORE_GID} qore
39+
fi
40+
if ! grep -q "^qore:x:${QORE_UID}" /etc/passwd; then
41+
adduser -u ${QORE_UID} -D -G qore -h /home/qore -s /bin/bash qore
42+
fi
43+
44+
# own everything by the qore user
45+
chown -R qore:qore ${MODULE_SRC_DIR}
46+
47+
# run the tests
48+
export QORE_MODULE_DIR=${MODULE_SRC_DIR}/qlib:${QORE_MODULE_DIR}
49+
cd ${MODULE_SRC_DIR}
50+
for test in test/*.qtest; do
51+
gosu qore:qore qore $test -vv
52+
done

test/docker_test/test.sh renamed to test/docker_test/test-ubuntu.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ENV_FILE=/tmp/env.sh
99

1010
# setup MODULE_SRC_DIR env var
1111
cwd=`pwd`
12-
if [ "${MODULE_SRC_DIR}" = "" ]; then
12+
if [ -z "${MODULE_SRC_DIR}" ]; then
1313
if [ -e "$cwd/src/processpriv.cpp" ] || [ -e "$cwd/src/process.qpp" ]; then
1414
MODULE_SRC_DIR=$cwd
1515
else
@@ -27,9 +27,8 @@ export MAKE_JOBS=4
2727

2828
# build module and install
2929
echo && echo "-- building module --"
30-
cd ${MODULE_SRC_DIR}
31-
mkdir build
32-
cd build
30+
mkdir -p ${MODULE_SRC_DIR}/build
31+
cd ${MODULE_SRC_DIR}/build
3332
cmake .. -DCMAKE_BUILD_TYPE=debug -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX}
3433
make -j${MAKE_JOBS}
3534
make install
@@ -46,4 +45,4 @@ export QORE_MODULE_DIR=${MODULE_SRC_DIR}/qlib:${QORE_MODULE_DIR}
4645
cd ${MODULE_SRC_DIR}
4746
for test in test/*.qtest; do
4847
gosu qore:qore qore $test -vv
49-
done
48+
done

test/process.qtest

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
our *softbool VERBOSE;
1313
our Main MAIN;
1414

15+
bool sub isAlpine() {
16+
return (ENV.MACHTYPE ?? "").find("alpine") > -1;
17+
}
18+
1519
class EmptyClass {
1620
constructor() {}
1721
}
@@ -45,7 +49,8 @@ public class Main inherits QUnit::Test {
4549
"searchPathTest_out": "^(/usr)?/bin/ls$",
4650
"simpleTest_exe": "ls",
4751
"simpleTest_arg": ("-l", "-s",),
48-
"executorsTest_success": "Success",
52+
"executorsTest_success": isAlpine() ? "No error information" : "Success",
53+
"executorsTest_exit_code_127": isAlpine() ? 383 : 127,
4954
},
5055
"WINDOWS": {
5156
"searchPathTest_in": "timeout",
@@ -398,7 +403,7 @@ public class Main inherits QUnit::Test {
398403
printf(" on_success attribute: %y\n", e);
399404

400405
assertEq("on_success", e.name, "name check");
401-
assertEq(127, e.exit, "on_success exit code check");
406+
assertEq(getTestValue("executorsTest_exit_code_127"), e.exit, "on_success exit code check");
402407
assertEq(m_prefix + getTestValue("testTrue"), e.exe, "on_success exe check");
403408
assertEq(0, e.error_code, "on_success error_code check");
404409
assertEq(getTestValue("executorsTest_success"), e.error_message, "on_success error_message check");
@@ -441,7 +446,7 @@ public class Main inherits QUnit::Test {
441446
printf("executorMethod: %y\n", e);
442447

443448
assertEq("on_success", e.name, "name check");
444-
assertEq(127, e.exit, "on_success exit code check");
449+
assertEq(getTestValue("executorsTest_exit_code_127"), e.exit, "on_success exit code check");
445450
assertEq(m_prefix + getTestValue("testTrue"), e.exe, "on_success exe check");
446451
assertEq(0, e.error_code, "on_success error_code check");
447452
assertEq(getTestValue("executorsTest_success"), e.error_message, "on_success error_message check");
@@ -453,7 +458,7 @@ public class Main inherits QUnit::Test {
453458
printf("executorStaticMethod: %y\n", e);
454459

455460
MAIN.assertEq("on_success", e.name, "name check");
456-
MAIN.assertEq(127, e.exit, "on_success exit code check");
461+
MAIN.assertEq(MAIN.getTestValue("executorsTest_exit_code_127"), e.exit, "on_success exit code check");
457462
MAIN.assertEq(MAIN.prefix() + MAIN.getTestValue("testTrue"), e.exe, "on_success exe check");
458463
MAIN.assertEq(0, e.error_code, "on_success error_code check");
459464
MAIN.assertEq(MAIN.getTestValue("executorsTest_success"), e.error_message, "on_success error_message check");
@@ -466,7 +471,7 @@ public class Main inherits QUnit::Test {
466471
printf("executorNoHash: %y\n", e);
467472

468473
assertEq("on_success", e.name, "name check");
469-
assertEq(127, e.exit, "on_success exit code check");
474+
assertEq(getTestValue("executorsTest_exit_code_127"), e.exit, "on_success exit code check");
470475
assertEq(m_prefix + getTestValue("testTrue"), e.exe, "on_success exe check");
471476
assertEq(0, e.error_code, "on_success error_code check");
472477
assertEq(getTestValue("executorsTest_success"), e.error_message, "on_success error_message check");
@@ -829,7 +834,7 @@ sub run_bg(Counter cnt, Process p, Main m) {
829834
sub executor_func(hash<auto> e) {
830835
if (VERBOSE > 2) printf("executor_func: %y\n", e);
831836
MAIN.assertEq("on_success", e.name, "name check");
832-
MAIN.assertEq(127, e.exit, "on_success exit code check");
837+
MAIN.assertEq(MAIN.getTestValue("executorsTest_exit_code_127"), e.exit, "on_success exit code check");
833838
MAIN.assertEq(MAIN.prefix() + MAIN.getTestValue("testTrue"), e.exe, "on_success exe check");
834839
MAIN.assertEq(0, e.error_code, "on_success error_code check");
835840
MAIN.assertEq(MAIN.getTestValue("executorsTest_success"), e.error_message, "on_success error_message check");

0 commit comments

Comments
 (0)