|
| 1 | +#!/bin/sh |
| 2 | +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. |
| 3 | +# SPDX-License-Identifier: BSD-3-Clause-Clear |
| 4 | + |
| 5 | +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 6 | + |
| 7 | +# ---- Source init_env & tools ---- |
| 8 | +INIT_ENV="" |
| 9 | +SEARCH="$SCRIPT_DIR" |
| 10 | +while [ "$SEARCH" != "/" ]; do |
| 11 | + if [ -f "$SEARCH/init_env" ]; then INIT_ENV="$SEARCH/init_env"; break; fi |
| 12 | + SEARCH="$(dirname "$SEARCH")" |
| 13 | +done |
| 14 | +if [ -z "$INIT_ENV" ]; then |
| 15 | + echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2 |
| 16 | + exit 1 |
| 17 | +fi |
| 18 | + |
| 19 | +# Only source if not already loaded (idempotent) |
| 20 | +if [ -z "$__INIT_ENV_LOADED" ]; then |
| 21 | + # shellcheck disable=SC1090 |
| 22 | + . "$INIT_ENV" |
| 23 | +fi |
| 24 | +# Always source functestlib.sh, using $TOOLS exported by init_env |
| 25 | +# shellcheck disable=SC1090,SC1091 |
| 26 | +. "$TOOLS/functestlib.sh" |
| 27 | + |
| 28 | +TESTNAME="core_auth" |
| 29 | +result_file="./${TESTNAME}.res" |
| 30 | +CORE_AUTH_CMD="" |
| 31 | + |
| 32 | +test_path="$(find_test_case_by_name "$TESTNAME" 2>/dev/null)" |
| 33 | +if [ -z "$test_path" ] || [ ! -d "$test_path" ]; then |
| 34 | + test_path="$SCRIPT_DIR" |
| 35 | +fi |
| 36 | + |
| 37 | +if [ ! -w "$test_path" ]; then |
| 38 | + log_error "Cannot write to test directory: $test_path" |
| 39 | + echo "$TESTNAME FAIL" >"$result_file" |
| 40 | + exit 1 |
| 41 | +fi |
| 42 | + |
| 43 | +while [ $# -gt 0 ]; do |
| 44 | + case "$1" in |
| 45 | + --core-auth-path) |
| 46 | + shift |
| 47 | + if [ -n "${1:-}" ]; then |
| 48 | + CORE_AUTH_CMD="$1" |
| 49 | + else |
| 50 | + log_error "Missing value for --core-auth-path parameter" |
| 51 | + echo "$TESTNAME FAIL" >"$result_file" |
| 52 | + exit 1 |
| 53 | + fi |
| 54 | + ;; |
| 55 | + --help|-h) |
| 56 | + log_info "Usage: $0 [--core-auth-path BINARY_PATH] | [BINARY_PATH]" |
| 57 | + exit 0 |
| 58 | + ;; |
| 59 | + -*) |
| 60 | + log_warn "Unknown argument: $1" |
| 61 | + ;; |
| 62 | + *) |
| 63 | + if [ -z "$CORE_AUTH_CMD" ]; then |
| 64 | + CORE_AUTH_CMD="$1" |
| 65 | + else |
| 66 | + log_warn "Multiple paths specified, ignoring: $1" |
| 67 | + fi |
| 68 | + ;; |
| 69 | + esac |
| 70 | + shift |
| 71 | +done |
| 72 | + |
| 73 | +if ! cd "$test_path"; then |
| 74 | + log_error "cd failed: $test_path" |
| 75 | + echo "$TESTNAME FAIL" >"$result_file" |
| 76 | + exit 1 |
| 77 | +fi |
| 78 | + |
| 79 | +log_info "-------------------Starting $TESTNAME Testcase-----------------------------" |
| 80 | + |
| 81 | +if [ -z "$CORE_AUTH_CMD" ]; then |
| 82 | + log_error "core_auth binary not specified" |
| 83 | + echo "$TESTNAME FAIL" > "$result_file" |
| 84 | + exit 1 |
| 85 | +fi |
| 86 | + |
| 87 | +if [ ! -x "$CORE_AUTH_CMD" ]; then |
| 88 | + log_error "FAIL: core_auth binary not found or not executable at: $CORE_AUTH_CMD" |
| 89 | + echo "$TESTNAME FAIL" > "$result_file" |
| 90 | + exit 1 |
| 91 | +fi |
| 92 | + |
| 93 | +log_info "Using core_auth binary at: $CORE_AUTH_CMD" |
| 94 | + |
| 95 | +if ! weston_stop; then |
| 96 | + log_error "Failed to stop Weston" |
| 97 | + echo "$TESTNAME FAIL" > "$result_file" |
| 98 | + exit 1 |
| 99 | +fi |
| 100 | + |
| 101 | +log_file="$test_path/core_auth_log.txt" |
| 102 | +"$CORE_AUTH_CMD" > "$log_file" 2>&1 |
| 103 | +RC="$?" |
| 104 | + |
| 105 | +log_info "Logs written to: $log_file" |
| 106 | + |
| 107 | +success_count=$(grep -c "SUCCESS" "$log_file" 2>/dev/null || echo "0") |
| 108 | +fail_count=$(grep -c "FAIL" "$log_file" 2>/dev/null || echo "0") |
| 109 | +skip_count=$(grep -c "SKIP" "$log_file" 2>/dev/null || echo "0") |
| 110 | + |
| 111 | +# Ensure we have valid numbers |
| 112 | +success_count=${success_count:-0} |
| 113 | +fail_count=${fail_count:-0} |
| 114 | +skip_count=${skip_count:-0} |
| 115 | + |
| 116 | +case "$success_count" in ''|*[!0-9]*) success_count=0 ;; esac |
| 117 | +case "$fail_count" in ''|*[!0-9]*) fail_count=0 ;; esac |
| 118 | +case "$skip_count" in ''|*[!0-9]*) skip_count=0 ;; esac |
| 119 | + |
| 120 | +total_subtests=$((success_count + fail_count + skip_count)) |
| 121 | + |
| 122 | +log_info "Subtest Results: SUCCESS=$success_count, FAIL=$fail_count, SKIP=$skip_count, TOTAL=$total_subtests" |
| 123 | +log_info "results will be written to \"$result_file\"" |
| 124 | +log_info "-------------------Completed $TESTNAME Testcase----------------------------" |
| 125 | + |
| 126 | +if [ "$RC" -ne 0 ]; then |
| 127 | + log_fail "$TESTNAME : Test Failed (exit code: $RC)" |
| 128 | + echo "$TESTNAME FAIL" > "$result_file" |
| 129 | + exit 1 |
| 130 | +elif [ "$fail_count" -gt 0 ]; then |
| 131 | + log_fail "$TESTNAME : Test Failed - $fail_count subtest(s) failed out of $total_subtests" |
| 132 | + echo "$TESTNAME FAIL" > "$result_file" |
| 133 | + exit 1 |
| 134 | +elif [ "$skip_count" -gt 0 ] && [ "$success_count" -eq 0 ]; then |
| 135 | + log_skip "$TESTNAME : Test Skipped - All $skip_count subtest(s) were skipped" |
| 136 | + echo "$TESTNAME SKIP" > "$result_file" |
| 137 | + exit 0 |
| 138 | +else |
| 139 | + if [ "$success_count" -gt 0 ]; then |
| 140 | + if [ "$skip_count" -gt 0 ]; then |
| 141 | + log_pass "$TESTNAME : Test Passed - $success_count subtest(s) succeeded, $skip_count skipped" |
| 142 | + else |
| 143 | + log_pass "$TESTNAME : Test Passed - All $success_count subtest(s) succeeded" |
| 144 | + fi |
| 145 | + else |
| 146 | + log_pass "$TESTNAME : Test Passed (return code $RC)" |
| 147 | + fi |
| 148 | + echo "$TESTNAME PASS" > "$result_file" |
| 149 | + exit 0 |
| 150 | +fi |
0 commit comments