import sys, os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', 'tests'))
from security_framework import SecurityTestFramework
config = {
'tool_name': 'seq',
'bin_name': 'fseq',
'gnu_path': '/usr/bin/seq',
'bss_size': 131072,
'max_binary_size': 100000,
'test_args': ['5'],
'test_stdin': None,
'timeout': 5,
}
def tool_specific_tests(fw):
fw.log("\n=== Seq-Specific Tests ===")
rc_a, out_a, _ = fw.run_asm(["5"])
rc_g, out_g, _ = fw.run_gnu(["5"])
fw.report_result(out_a == out_g, "seq: seq 5 matches GNU")
fw.report_result(out_a == b"1\n2\n3\n4\n5\n", "seq: seq 5 correct output")
rc_a, out_a, _ = fw.run_asm(["3", "7"])
rc_g, out_g, _ = fw.run_gnu(["3", "7"])
fw.report_result(out_a == out_g, "seq: seq 3 7 matches GNU")
rc_a, out_a, _ = fw.run_asm(["1", "2", "10"])
rc_g, out_g, _ = fw.run_gnu(["1", "2", "10"])
fw.report_result(out_a == out_g, "seq: seq 1 2 10 matches GNU")
fw.report_result(out_a == b"1\n3\n5\n7\n9\n", "seq: seq 1 2 10 correct output")
rc_a, out_a, _ = fw.run_asm(["1"])
rc_g, out_g, _ = fw.run_gnu(["1"])
fw.report_result(out_a == out_g, "seq: seq 1 matches GNU")
rc_a, out_a, _ = fw.run_asm(["0"])
rc_g, out_g, _ = fw.run_gnu(["0"])
fw.report_result(out_a == out_g, "seq: seq 0 matches GNU")
rc_a, out_a, _ = fw.run_asm(["5", "1"])
rc_g, out_g, _ = fw.run_gnu(["5", "1"])
fw.report_result(out_a == out_g, "seq: empty range (5 1) matches GNU")
fw.report_result(out_a == b"", "seq: empty range produces no output")
rc_a, out_a, _ = fw.run_asm(["-3", "3"])
rc_g, out_g, _ = fw.run_gnu(["-3", "3"])
fw.report_result(out_a == out_g, "seq: negative start (-3 3) matches GNU")
rc_a, out_a, _ = fw.run_asm(["5", "-1", "1"])
rc_g, out_g, _ = fw.run_gnu(["5", "-1", "1"])
fw.report_result(out_a == out_g, "seq: counting down (5 -1 1) matches GNU")
fw.report_result(out_a == b"5\n4\n3\n2\n1\n", "seq: counting down correct output")
rc_a, out_a, _ = fw.run_asm(["2", "-1", "-2"])
rc_g, out_g, _ = fw.run_gnu(["2", "-1", "-2"])
fw.report_result(out_a == out_g, "seq: counting down to negative matches GNU")
rc_a, out_a, _ = fw.run_asm(["-w", "1", "10"])
rc_g, out_g, _ = fw.run_gnu(["-w", "1", "10"])
fw.report_result(out_a == out_g, "seq: -w zero padding matches GNU")
first_line = out_a.split(b"\n")[0]
fw.report_result(first_line == b"01", "seq: -w pads '1' to '01'")
rc_a, out_a, _ = fw.run_asm(["-s", ",", "5"])
rc_g, out_g, _ = fw.run_gnu(["-s", ",", "5"])
fw.report_result(out_a == out_g, "seq: -s comma separator matches GNU")
fw.report_result(out_a == b"1,2,3,4,5\n", "seq: -s comma correct output")
rc_a, out_a, _ = fw.run_asm(["-s", " ", "3"])
rc_g, out_g, _ = fw.run_gnu(["-s", " ", "3"])
fw.report_result(out_a == out_g, "seq: -s space separator matches GNU")
rc_a, out_a, _ = fw.run_asm(["0.5"])
rc_g, out_g, _ = fw.run_gnu(["0.5"])
fw.report_result(out_a == out_g, "seq: float seq 0.5 matches GNU")
rc_a, out_a, _ = fw.run_asm(["0.1", "0.1", "0.5"])
rc_g, out_g, _ = fw.run_gnu(["0.1", "0.1", "0.5"])
fw.report_result(out_a == out_g, "seq: float seq 0.1 0.1 0.5 matches GNU")
rc_a, out_a, _ = fw.run_asm(["1", "1000"], timeout=10)
rc_g, out_g, _ = fw.run_gnu(["1", "1000"], timeout=10)
fw.report_result(out_a == out_g, "seq: seq 1 1000 matches GNU")
fw.report_result(len(out_a.strip().split(b"\n")) == 1000, "seq: seq 1 1000 has 1000 lines")
rc_a, _, _ = fw.run_asm([])
fw.report_result(rc_a != 0, "seq: no args returns nonzero")
rc_a, _, _ = fw.run_asm(["abc"])
fw.report_result(rc_a != 0, "seq: invalid number returns nonzero")
rc_a, _, _ = fw.run_asm(["1", "2", "3", "4"])
fw.report_result(rc_a != 0, "seq: too many args returns nonzero")
rc_a, out_a, _ = fw.run_asm(["--help"])
fw.report_result(rc_a == 0 and len(out_a) > 0, "seq: --help works")
rc_a, out_a, _ = fw.run_asm(["--version"])
fw.report_result(rc_a == 0 and len(out_a) > 0, "seq: --version works")
rc_a, _, _ = fw.run_asm(["1", "0", "5"])
fw.report_result(rc_a != 0, "seq: step 0 returns nonzero")
rc_a, out_a, _ = fw.run_asm(["1", "10000"], timeout=10)
rc_g, out_g, _ = fw.run_gnu(["1", "10000"], timeout=10)
fw.report_result(out_a == out_g, "seq: seq 1 10000 matches GNU exactly")
if __name__ == '__main__':
fw = SecurityTestFramework(config)
fw.run_all(tool_specific_fn=tool_specific_tests)