about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-06-28 16:54:41 -0700
committerKartik Agaram <vc@akkartik.com>2019-06-28 16:54:41 -0700
commita7e21dbdf7d1492f850c0bf1404835ba56e71e8a (patch)
tree6e1748f8db7d4595f4774ad0c41086cf79de2381
parent5be5fcd7eb4ea3e6e042e682ac56a1a65e6ebd92 (diff)
downloadmu-a7e21dbdf7d1492f850c0bf1404835ba56e71e8a.tar.gz
.
Flesh out final test some more. We also now have a new family of
primitives for writing non-strings to input streams in tests.
-rwxr-xr-xsubx/apps/surveybin26365 -> 27549 bytes
-rw-r--r--subx/apps/survey.subx167
2 files changed, 155 insertions, 12 deletions
diff --git a/subx/apps/survey b/subx/apps/survey
index c65cd5c4..1fd5cd5d 100755
--- a/subx/apps/survey
+++ b/subx/apps/survey
Binary files differdiff --git a/subx/apps/survey.subx b/subx/apps/survey.subx
index be16ed0f..a73bb661 100644
--- a/subx/apps/survey.subx
+++ b/subx/apps/survey.subx
@@ -567,17 +567,17 @@ $compute-addresses:end:
     c3/return
 
 test-compute-addresses:
-    # segment-info:
-    #   - {'a', 0x1000, 5, 0}
-    #   - {'b', 0x500, 1, 0}
-    #   - {'c', 0x5444, 12, 0}
-    # label-info:
-    #   - {'l1', 'code', 3, 0}
-    #   - {'l2', 'data', 0, 0}
+    # segments:
+    #   - 'a': {0x1000, 0, 5}
+    #   - 'b': {0x500, 0, 1}
+    #   - 'c': {0x5444, 0, 12}
+    # labels:
+    #   - 'l1': {'a', 3, 0}
+    #   - 'l2': {'b', 0, 0}
     #
     # trace contains (in any order):
-    #   segment 'code starts at address 0x1074
-    #   segment 'data starts at address 0x579
+    #   segment 'a' starts at address 0x1074
+    #   segment 'b' starts at address 0x579
     #   label 'l1' is at address 0x1077
     #   label 'l2' is at address 0x579
     #
@@ -585,15 +585,78 @@ test-compute-addresses:
     55/push-EBP
     89/copy                         3/mod/direct    5/rm32/EBP    .           .             .           4/r32/ESP   .               .                 # copy ESP to EBP
     # setup
-    # . check-trace-contains("segment 'code' starts at address 0x1074", msg)
+    # . var segments/ECX = stream(10 * 16)
+    81          5/subop/subtract    3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xa0/imm32        # subtract from ESP
+    68/push  0xa0/imm32/length
+    68/push  0/imm32/read
+    68/push  0/imm32/write
+    89/copy                         3/mod/direct    1/rm32/ECX    .           .             .           4/r32/ESP   .               .                 # copy ESP to ECX
+    # . var labels/EDX = stream(512 * 16)
+    81          5/subop/subtract    3/mod/direct    4/rm32/ESP    .           .             .           .           .               0x2000/imm32      # subtract from ESP
+    68/push  0x2000/imm32/length
+    68/push  0/imm32/read
+    68/push  0/imm32/write
+    89/copy                         3/mod/direct    2/rm32/EDX    .           .             .           4/r32/ESP   .               .                 # copy ESP to EDX
+    # . stream-add4(segments, "a", 0x1000, 0, 5)
+    68/push  5/imm32/segment-size
+    68/push  0/imm32/file-offset
+    68/push  0x1000/imm32/start-address
+    68/push  "a"/imm32/segment-name
+    51/push-ECX
+    # . . call
+    e8/call  stream-add4/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0x14/imm32        # add to ESP
+    # . stream-add4(segments, "b", 0x500, 0, 1)
+    68/push  1/imm32/segment-size
+    68/push  0/imm32/file-offset
+    68/push  0x500/imm32/start-address
+    68/push  "b"/imm32/segment-name
+    51/push-ECX
+    # . . call
+    e8/call  stream-add4/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0x14/imm32        # add to ESP
+    # . stream-add4(segments, "c", 0x5444, 0, 12)
+    68/push  0xc/imm32/segment-size
+    68/push  0/imm32/file-offset
+    68/push  0x5444/imm32/start-address
+    68/push  "c"/imm32/segment-name
+    51/push-ECX
+    # . . call
+    e8/call  stream-add4/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0x14/imm32        # add to ESP
+    # . stream-add4(labels, "l1", "a", 3, 0)
+    68/push  0/imm32/label-address
+    68/push  3/imm32/segment-offset
+    68/push  "a"/imm32/segment-name
+    68/push  "l1"/imm32/label-name
+    52/push-EDX
+    # . . call
+    e8/call  stream-add4/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0x14/imm32        # add to ESP
+    # . stream-add4(labels, "l2", "b", 0, 0)
+    68/push  0/imm32/label-address
+    68/push  0/imm32/segment-offset
+    68/push  "b"/imm32/segment-name
+    68/push  "l2"/imm32/label-name
+    52/push-EDX
+    # . . call
+    e8/call  stream-add4/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0x14/imm32        # add to ESP
+    # checks
+    # . check-trace-contains("segment 'a' starts at address 0x1074", msg)
     # . . push args
     68/push  "F - test-compute-addresses/0"/imm32
-    68/push  "segment 'code' starts at address 0x1074"/imm32
+    68/push  "segment 'a' starts at address 0x1074"/imm32
     # . . call
     e8/call  check-trace-contains/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
-    # . check-trace-contains("segment 'data' starts at address 0x579", msg)
+    # . check-trace-contains("segment 'b' starts at address 0x579", msg)
     # . . push args
     68/push  "F - test-compute-addresses/1"/imm32
     68/push  "segment 'data' starts at address 0x579"/imm32
@@ -622,6 +685,86 @@ test-compute-addresses:
     5d/pop-to-EBP
     c3/return
 
+# helper for tests
+stream-add4:  # in : (address stream byte), key : address, val1 : address, val2 : address, val3 : address
+    # . prolog
+    55/push-EBP
+    89/copy                         3/mod/direct    5/rm32/EBP    .           .             .           4/r32/ESP   .               .                 # copy ESP to EBP
+    # . save registers
+    50/push-EAX
+    51/push-ECX
+    52/push-EDX
+    56/push-ESI
+    # ESI = in
+    8b/copy                         1/mod/*+disp8   5/rm32/EBP    .           .                         6/r32/ESI   8/disp8         .                 # copy *(EBP+8) to ESI
+    # curr/EAX = in->data + in->write
+    # . EAX = in->write
+    8b/copy                         0/mod/indirect  6/rm32/ESI    .           .             .           0/r32/EAX   .               .                 # copy *ESI to EAX
+    # . EAX = ESI+EAX+12
+    8d/copy-address                 1/mod/*+disp8   4/rm32/sib    6/base/ESI  0/index/EAX   .           0/r32/EAX   0xc/disp8       .                 # copy ESI+EAX+12 to EAX
+    # max/EDX = in->data + in->length
+    # . EDX = in->length
+    8b/copy                         1/mod/*+disp8   6/rm32/ESI    .           .             .           2/r32/EDX   8/disp8         .                 # copy *(ESI+8) to EDX
+    # . EDX = ESI+EDX+12
+    8d/copy-address                 1/mod/*+disp8   4/rm32/sib    6/base/ESI  2/index/EDX   .           2/r32/EDX   0xc/disp8       .                 # copy ESI+EDX+12 to EDX
+    # if (curr >= max) abort
+    39/compare                      3/mod/direct    0/rm32/EAX    .           .             .           2/r32/EDX   .               .                 # compare EAX with EDX
+    73/jump-if-greater-or-equal-unsigned  $stream-add4:abort/disp8
+    # *curr = key
+    8b/copy                         1/mod/*+disp8   5/rm32/EBP    .           .                         1/r32/ECX   0xc/disp8       .                 # copy *(EBP+12) to ECX
+    89/copy                         0/mod/indirect  0/rm32/EAX    .           .             .           1/r32/ECX   .               .                 # copy ECX to *EAX
+    # curr += 4
+    05/add-to-EAX  4/imm32
+    # if (curr >= max) abort
+    39/compare                      3/mod/direct    0/rm32/EAX    .           .             .           2/r32/EDX   .               .                 # compare EAX with EDX
+    73/jump-if-greater-or-equal-unsigned  $stream-add4:abort/disp8
+    # *curr = val1
+    8b/copy                         1/mod/*+disp8   5/rm32/EBP    .           .                         1/r32/ECX   0x10/disp8      .                 # copy *(EBP+16) to ECX
+    89/copy                         0/mod/indirect  0/rm32/EAX    .           .             .           1/r32/ECX   .               .                 # copy ECX to *EAX
+    # curr += 4
+    05/add-to-EAX  4/imm32
+    # if (curr >= max) abort
+    39/compare                      3/mod/direct    0/rm32/EAX    .           .             .           2/r32/EDX   .               .                 # compare EAX with EDX
+    73/jump-if-greater-or-equal-unsigned  $stream-add4:abort/disp8
+    # *curr = val2
+    8b/copy                         1/mod/*+disp8   5/rm32/EBP    .           .                         1/r32/ECX   0x14/disp8      .                 # copy *(EBP+20) to ECX
+    89/copy                         0/mod/indirect  0/rm32/EAX    .           .             .           1/r32/ECX   .               .                 # copy ECX to *EAX
+    # curr += 4
+    05/add-to-EAX  4/imm32
+    # if (curr >= max) abort
+    39/compare                      3/mod/direct    0/rm32/EAX    .           .             .           2/r32/EDX   .               .                 # compare EAX with EDX
+    73/jump-if-greater-or-equal-unsigned  $stream-add4:abort/disp8
+    # *curr = val3
+    8b/copy                         1/mod/*+disp8   5/rm32/EBP    .           .                         1/r32/ECX   0x18/disp8      .                 # copy *(EBP+24) to ECX
+    89/copy                         0/mod/indirect  0/rm32/EAX    .           .             .           1/r32/ECX   .               .                 # copy ECX to *EAX
+    # in->write += 16
+    81          0/subop/add         0/mod/indirect  6/rm32/ESI    .           .             .           .           .               0x10/imm32        # add to *ESI
+$stream-add4:end:
+    # . restore registers
+    5e/pop-to-ESI
+    5a/pop-to-EDX
+    59/pop-to-ECX
+    58/pop-to-EAX
+    # . epilog
+    89/copy                         3/mod/direct    4/rm32/ESP    .           .             .           5/r32/EBP   .               .                 # copy EBP to ESP
+    5d/pop-to-EBP
+    c3/return
+
+$stream-add4:abort:
+    # . _write(2/stderr, error)
+    # . . push args
+    68/push  "overflow in stream-add4\n"/imm32
+    68/push  2/imm32/stderr
+    # . . call
+    e8/call  _write/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
+    # . syscall(exit, 1)
+    bb/copy-to-EBX  1/imm32
+    b8/copy-to-EAX  1/imm32/exit
+    cd/syscall  0x80/imm8
+    # never gets here
+
 emit-output:  # in : (address buffered-file), out : (address buffered-file), segments : (address stream {string, segment-info}), labels : (address stream {string, label-info})
     # pseudocode:
     #   emit-headers(out, segments, labels)