1# Copyright (c) 2024 Intel Corporation
2#
3# SPDX-License-Identifier: Apache-2.0
4import pytest
5from twister_harness import Shell
6
7def test_run_all_shuffled(shell: Shell):
8    lines = shell.exec_command('ztest shuffle -c 1 -s 1')
9    # Join the list of lines into a single string
10    output = '\n'.join(lines)
11    assert "PASS - test_int_param" in output, f"Expected 'PASS - test_int_param' but got {lines}"
12    assert "PASS - test_dummy" in output, f"Expected 'PASS - test_dummy' but got {lines}"
13    assert "PASS - test_string_param" in output, f"Expected 'PASS - test_string_param' but got {lines}"
14
15def test_run_testcase_once(shell: Shell):
16    lines = shell.exec_command('ztest run-testcase ztest_params::test_dummy')
17    # Join the list of lines into a single string
18    output = '\n'.join(lines)
19    assert "PASS - test_dummy" in output, f"Expected 'PASS - test_dummy' but got {lines}"
20
21# def test_run_testcase_twice(shell: Shell):
22    lines = shell.exec_command('ztest run-testcase ztest_params::test_dummy -r 2')
23    # Join the list of lines into a single string
24    output = '\n'.join(lines)
25    pass_dummy_count = output.count("PASS - test_dummy")
26    assert pass_dummy_count == 2, f"Expected 2 occurrences of 'PASS - test_dummy' but found {pass_dummy_count}"
27
28def test_run_testsuite_twice(shell: Shell):
29    lines = shell.exec_command('ztest run-testsuite ztest_params -r 2')
30    # Join the list of lines into a single string
31    output = '\n'.join(lines)
32    pass_ztest_params_count = output.count("TESTSUITE ztest_params succeeded")
33    assert pass_ztest_params_count == 2, f"Expected 2 occurrences of 'TESTSUITE ztest_params succeeded' but found {pass_ztest_params_count}"
34
35def test_run_testsuite_once(shell: Shell):
36    lines = shell.exec_command('ztest run-testsuite ztest_params')
37    # Join the list of lines into a single string
38    output = '\n'.join(lines)
39    assert "TESTSUITE ztest_params succeeded" in output, f"Expected 'TESTSUITE ztest_params succeeded' but got {lines}"
40
41def test_run_testcase_with_int_parameter(shell: Shell):
42    lines = shell.exec_command('ztest run-testcase ztest_params::test_int_param -p 44')
43    # Join the list of lines into a single string
44    output = '\n'.join(lines)
45    assert 'Passed int value:44' in output, 'expected response not found'
46
47@pytest.mark.parametrize("test_input", ["Testing", "Zephyr", "RTOS"])
48def test_run_testcase_with_string_parameter(shell: Shell, test_input):
49    lines = shell.exec_command(f'ztest run-testcase ztest_params::test_string_param -p {test_input}')
50    assert f'Passed string:{test_input}' in lines, 'expected response not found'
51