Skip to content

Commit d106b1e

Browse files
committed
Fix EXAMINE output for array register repeats
Adopt the fix from open-simh PR 502 for the bug described in upstream issue 499, and add local test coverage. When EXAMINE compresses repeated array register values, the old single-element repeat case printed the skipped element with the next different value. That made ranged output report an incorrect value for the skipped array slot. Remove that special case so every skipped repeated run is summarized as `same as above`, whether it contains one element or several. Add a focused SCP register unit test that reproduces the bad output before the fix and validates the corrected summary output.
1 parent 1f0fbfc commit d106b1e

4 files changed

Lines changed: 72 additions & 12 deletions

File tree

src/core/scp.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7876,18 +7876,10 @@ for (rptr = lowr; rptr <= highr; rptr++) {
78767876
if ((idx > lows) && (val == last_val))
78777877
continue;
78787878
if (idx > val_start+1) {
7879-
if (idx-1 == val_start+1) {
7880-
reason = ex_reg (ofile, val, flag, rptr, idx-1);
7881-
sim_switches = saved_switches;
7882-
if (reason != SCPE_OK)
7883-
return reason;
7884-
}
7885-
else {
7886-
if (val_start+1 != idx-1)
7887-
fprintf (ofile, "%s[%d]-%s[%d]: same as above\n", rptr->name, val_start+1, rptr->name, idx-1);
7888-
else
7889-
fprintf (ofile, "%s[%d]: same as above\n", rptr->name, val_start+1);
7890-
}
7879+
if (val_start+1 != idx-1)
7880+
fprintf (ofile, "%s[%d]-%s[%d]: same as above\n", rptr->name, val_start+1, rptr->name, idx-1);
7881+
else
7882+
fprintf (ofile, "%s[%d]: same as above\n", rptr->name, val_start+1);
78917883
}
78927884
sim_last_val = last_val = val;
78937885
val_start = idx;

src/core/scp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@
8282

8383
t_stat reset_cmd (int32 flag, const char *ptr);
8484
t_stat exdep_cmd (int32 flag, const char *ptr);
85+
t_stat exdep_reg_loop (FILE *ofile, SCHTAB *schptr, int32 flag,
86+
const char *cptr, REG *lowr, REG *highr, uint32 lows, uint32 highs);
8587
t_stat eval_cmd (int32 flag, const char *ptr);
8688
t_stat load_cmd (int32 flag, const char *ptr);
8789
t_stat run_cmd (int32 flag, const char *ptr);

tests/unit/src/core/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ add_unit_test(unit-scp-unit
2222
${PROJECT_SOURCE_DIR}/tests/unit/support
2323
)
2424

25+
add_unit_test(unit-scp-register
26+
LABEL unit
27+
SOURCES
28+
${CMAKE_CURRENT_SOURCE_DIR}/test_scp_register.c
29+
INCLUDES
30+
${PROJECT_SOURCE_DIR}/tests/unit/support
31+
)
32+
2533
add_unit_test(unit-scp-context
2634
LABEL unit
2735
SOURCES
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include <stddef.h>
2+
#include <setjmp.h>
3+
#include <stdlib.h>
4+
#include <string.h>
5+
6+
#include <cmocka.h>
7+
8+
#include "scp.h"
9+
#include "test_support.h"
10+
11+
static uint8 register_buffer[4];
12+
static REG test_registers[] = {
13+
{BRDATA(RBUF, register_buffer, 8, 8, 4)},
14+
{NULL},
15+
};
16+
17+
/* Verify summarized array output keeps skipped entries at their own value. */
18+
static void test_examine_array_register_summarizes_single_repeat(void **state)
19+
{
20+
FILE *stream;
21+
char *text = NULL;
22+
size_t size = 0;
23+
t_value eval[1] = {0};
24+
t_value *saved_eval = sim_eval;
25+
26+
(void)state;
27+
28+
sim_eval = eval;
29+
register_buffer[0] = 0;
30+
register_buffer[1] = 0;
31+
register_buffer[2] = 1;
32+
register_buffer[3] = 0;
33+
34+
stream = tmpfile();
35+
assert_non_null(stream);
36+
assert_int_equal(exdep_reg_loop(stream, NULL, EX_E, NULL,
37+
&test_registers[0], &test_registers[0], 0,
38+
3),
39+
SCPE_OK);
40+
assert_int_equal(simh_test_read_stream(stream, &text, &size), 0);
41+
assert_string_equal(text, "RBUF[0]:\t000\n"
42+
"RBUF[1]: same as above\n"
43+
"RBUF[2]:\t001\n"
44+
"RBUF[3]:\t000\n");
45+
46+
sim_eval = saved_eval;
47+
fclose(stream);
48+
free(text);
49+
}
50+
51+
int main(void)
52+
{
53+
const struct CMUnitTest tests[] = {
54+
cmocka_unit_test(test_examine_array_register_summarizes_single_repeat),
55+
};
56+
57+
return cmocka_run_group_tests(tests, NULL, NULL);
58+
}

0 commit comments

Comments
 (0)