From da2e4b767c06172a96230f8f699b9dba8d5596e2 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Fri, 16 Feb 2024 19:12:31 -0500 Subject: [PATCH] ci: Update test-git-branch for new status format Signed-off-by: Kent Overstreet --- ci-web/src/bin/get-test-job.rs | 7 ++++++- ci-web/src/lib.rs | 10 ++-------- ci/test-git-branch.sh | 8 ++++---- lib/parse-test.sh | 1 - lib/supervisor.c | 11 ++++------- lib/testrunner | 2 +- 6 files changed, 17 insertions(+), 22 deletions(-) diff --git a/ci-web/src/bin/get-test-job.rs b/ci-web/src/bin/get-test-job.rs index d0cbebb0..41af9b6b 100644 --- a/ci-web/src/bin/get-test-job.rs +++ b/ci-web/src/bin/get-test-job.rs @@ -76,7 +76,12 @@ fn lockfile_exists(rc: &Ktestrc, commit: &str, test_name: &str, create: bool) -> } } - r.is_ok() + if let Ok(mut r) = r { + let _ = r.write_all(b"{ \"status\": \"in progress\" }"); + true + } else { + false + } } } diff --git a/ci-web/src/lib.rs b/ci-web/src/lib.rs index 877925da..1c289fe7 100644 --- a/ci-web/src/lib.rs +++ b/ci-web/src/lib.rs @@ -104,7 +104,7 @@ impl TestStatus { pub struct TestResultJson { pub status: String, pub msg: Option, - pub duration: u64, + pub duration: Option, } #[derive(Clone, Debug)] @@ -124,18 +124,13 @@ fn commitdir_get_results_fs(commit_dir: &Path) -> TestResultsMap { f.read_to_string(&mut status_str).ok()?; let status_str = status_str.trim(); - - println!("status_str: {:?}", status_str); - let status_json: TestResultJson = serde_json::from_str(&status_str).ok()?; - println!("status_json: {:?}", status_json); - Some(TestResult { status: TestStatus::from_str(&status_json.status), msg: status_json.msg, starttime: f.metadata().ok()?.modified().ok()?.into(), - duration: status_json.duration, + duration: status_json.duration.unwrap_or(0), }) } @@ -146,7 +141,6 @@ fn commitdir_get_results_fs(commit_dir: &Path) -> TestResultsMap { if let Ok(results_dir) = results_dir { for d in results_dir.filter_map(|i| i.ok()) { let r = read_test_result(&d); - println!("{:?}", r); if let Some(r) = r { results.insert(d.file_name().into_string().unwrap(), r); } diff --git a/ci/test-git-branch.sh b/ci/test-git-branch.sh index 254f2f79..56fb5a4d 100755 --- a/ci/test-git-branch.sh +++ b/ci/test-git-branch.sh @@ -131,7 +131,7 @@ run_test_job() { t=$(echo "$t"|tr / .) mkdir ktest-out/out/$TEST_NAME.$t - echo "IN PROGRESS" > ktest-out/out/$TEST_NAME.$t/status + echo '{ "status": "in progress" }' > ktest-out/out/$TEST_NAME.$t/status done make -C "$KTEST_DIR/lib" supervisor @@ -159,14 +159,14 @@ run_test_job() { t=${SUBTESTS[0]} FNAME=$(echo "$t"|tr / .) - if grep -q "IN PROGRESS" ktest-out/out/$TEST_NAME.$FNAME/status; then - echo "NOT STARTED" > ktest-out/out/$TEST_NAME.$FNAME/status + if grep -q "in progress" ktest-out/out/$TEST_NAME.$FNAME/status; then + echo '{ "status": "not started" }' > ktest-out/out/$TEST_NAME.$FNAME/status fi for t in ${SUBTESTS[@]:1}; do FNAME=$(echo "$t"|tr / .) - if grep -q "IN PROGRESS" ktest-out/out/$TEST_NAME.$FNAME/status; then + if grep -q "in progress" ktest-out/out/$TEST_NAME.$FNAME/status; then SUBTESTS_REMAINING+=($t) fi done diff --git a/lib/parse-test.sh b/lib/parse-test.sh index 419cf57c..96b48997 100644 --- a/lib/parse-test.sh +++ b/lib/parse-test.sh @@ -20,7 +20,6 @@ parse_test_deps() if [[ -z $ktest_tests ]]; then echo "No tests found" - echo "TEST FAILED" exit 1 fi diff --git a/lib/supervisor.c b/lib/supervisor.c index f357cf07..9ffed11a 100644 --- a/lib/supervisor.c +++ b/lib/supervisor.c @@ -75,7 +75,7 @@ static void child_handler(int sig) static void alarm_handler(int sig) { - char *msg = mprintf("========= FAILED TIMEOUT %s in %lus\n", + char *msg = mprintf("========= FINISH { \"status\": \"failed\", \"duration\": %u }", current_test ?: "(no test)", timeout); if (write(childfd, msg, strlen(msg)) != strlen(msg)) @@ -217,7 +217,7 @@ static void test_start(char *new_test, struct timespec now) current_test_start = now; current_test_log = test_file_open("log"); - write_test_file("status", "TEST FAILED\n"); + write_test_file("status", "{ \"status\": \"failed\" }\n"); set_timeout(default_timeout); } @@ -349,13 +349,10 @@ int main(int argc, char *argv[]) test_end(); } - if (exit_on_failure && str_starts_with(line, "TEST FAILED")) + if (exit_on_failure && strstr(line, "failed")) break; - if (exit_on_failure && strstr(line, "FAILED TIMEOUT")) - break; - - if (exit_on_success && str_starts_with(line, "TEST SUCCESS")) { + if (exit_on_success && strstr(line, "success")) { ret = 0; break; } diff --git a/lib/testrunner b/lib/testrunner index 9a4c2122..10eb0231 100755 --- a/lib/testrunner +++ b/lib/testrunner @@ -134,7 +134,7 @@ check_taint() if [[ $taint != 0 ]]; then echo "Failure because kernel tainted - check log for warnings" - echo "TEST FAILED" + echo "========= FINISH { \"status\": \"failed\", }" exit 0 fi }