From d8b99a119926eabf1874545f864f9799cb6e6eb8 Mon Sep 17 00:00:00 2001 From: Folkert van Heusden Date: Fri, 4 Apr 2025 00:42:21 +0200 Subject: [PATCH] more test sets --- PDP11/test.c | 147 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 97 insertions(+), 50 deletions(-) diff --git a/PDP11/test.c b/PDP11/test.c index 51613890..4c159623 100644 --- a/PDP11/test.c +++ b/PDP11/test.c @@ -23,6 +23,37 @@ struct mem_t { uint16_t value; }; +int is_prime(int n) { + if (n <= 1) + return 0; + for(int i = 2; i*i <= n; i++) { + if (n % i == 0) + return 0; + } + return 1; +} + +uint16_t test_values[65536]; +int n_test_values = 0; + +void generate_test_values() +{ + for(int i=0; i<65536; i++) { + if (is_prime(i)) + test_values[n_test_values++] = i; + } + + for(int i=2; i<16; i++) + test_values[n_test_values++] = 1 << i; + + test_values[n_test_values++] = 0; + test_values[n_test_values++] = 255; + test_values[n_test_values++] = 256; + test_values[n_test_values++] = 32767; + test_values[n_test_values++] = 32768; + test_values[n_test_values++] = 65535; +} + json_t *generate_test(uint16_t instruction, int *const id, struct mem_t *mem, size_t n_mem) { json_t *before = json_object(); @@ -137,6 +168,7 @@ void init_stack_registers() void emit_branch_instructions(json_t *const target, int *const id) { + printf("Branch instructions\n"); for(int group=0; group<2; group++) { for(int bt=0; bt<8; bt++) { uint16_t instr = (group << 15) | (bt << 8); @@ -164,67 +196,82 @@ void emit_branch_instructions(json_t *const target, int *const id) } } +void emit_condition_sets(json_t *const target, int *const id) +{ + printf("Condition set instructions\n"); + for(int condition=0; condition<16; condition++) { + uint16_t instr = 0240 + condition; + + for(int psw_val=0; psw_val<16; psw_val++) { + init_simh(); + + saved_PC = 0100; + + randomize_registers_all_values(); + + init_stack_registers(); + + struct mem_t mem[1] = { + { 0100, instr } + }; + + PSW = psw_val; + + json_t *obj = generate_test(instr, id, mem, 1); + if (obj) + json_array_append_new(target, obj); + } + } +} + +void emit_add_sub(json_t *const target, int *const id) +{ + printf("ADD/SUB instructions\n"); + for(int group=0; group<2; group++) { + uint16_t instr = (6 << 12 /* instr */) | (group << 15 /* ADD/SUB */) | (1 << 6 /* src=R1 */); + + for(int v1=0; v1= invalid[test][0] && i <= invalid[test][1]) { - skip = 1; - break; - } - } - if (skip) - continue; - - if (i == 0 || // HALT - i == 1 || // WAIT - i == 5) // RESET - continue; - - if (i >= 0170000 && i <= 0177777) // FPU - continue; - - init_simh(); - - saved_PC = 0100; - for(int k=0; k<6; k++) { - REGFILE[k][0] = (rand() % 0160000) & (~1); - REGFILE[k][1] = (rand() % 0160000) & (~1); - } - - STACKFILE[0] = STACKFILE[1] = STACKFILE[2] = STACKFILE[3] = 010000; - - struct mem_t mem[3] = { - { 0100, i }, - { 0102, (rand() % 0160000) & (~1) }, - { 0104, (rand() % 0160000) & (~1) }, - }; - - PSW = rand() & 15; // only calculation status bits - - json_t *collection = generate_test(i, &id, mem, 3); - json_array_append_new(out, collection); - } -#endif emit_branch_instructions(out, &id); + emit_condition_sets(out, &id); + + emit_add_sub(out, &id); + FILE *fh = fopen("testset.json", "w"); json_dumpf(out, fh, JSON_INDENT(2)); fclose(fh);