diff options
Diffstat (limited to 'tests/library')
| -rw-r--r-- | tests/library/exp-memory/case.json | 1 | ||||
| -rw-r--r-- | tests/library/exp-memory/expected-stderr.txt | 3 | ||||
| -rw-r--r-- | tests/library/exp-memory/expected.txt | 17 | ||||
| -rw-r--r-- | tests/library/exp-memory/notes.md | 3 | ||||
| -rw-r--r-- | tests/library/exp-memory/program.cps | 76 | ||||
| -rw-r--r-- | tests/library/exp-string/case.json | 2 | ||||
| -rw-r--r-- | tests/library/exp-string/program.cps | 2 |
7 files changed, 102 insertions, 2 deletions
diff --git a/tests/library/exp-memory/case.json b/tests/library/exp-memory/case.json new file mode 100644 index 0000000..7a60233 --- /dev/null +++ b/tests/library/exp-memory/case.json @@ -0,0 +1 @@ +{"sources":["program.cps","../../../pseudocode-lib/memory.cps"],"compiler_args":["-no-std"]} diff --git a/tests/library/exp-memory/expected-stderr.txt b/tests/library/exp-memory/expected-stderr.txt new file mode 100644 index 0000000..9ade8ef --- /dev/null +++ b/tests/library/exp-memory/expected-stderr.txt @@ -0,0 +1,3 @@ +[Fatal] line 63: Invalid memory address (not an active allocation) +[Fatal] line 68: Memory allocation failed +[Fatal] line 73: Memory allocation failed diff --git a/tests/library/exp-memory/expected.txt b/tests/library/exp-memory/expected.txt new file mode 100644 index 0000000..b2272a2 --- /dev/null +++ b/tests/library/exp-memory/expected.txt @@ -0,0 +1,17 @@ +TRUETRUE +TRUETRUE +TRUETRUE +TRUETRUE +TRUETRUE +TRUETRUE +TRUETRUE +TRUETRUE +TRUETRUE +TRUETRUE +TRUETRUE +TRUETRUE +7 +17 +1 +2 +3 diff --git a/tests/library/exp-memory/notes.md b/tests/library/exp-memory/notes.md new file mode 100644 index 0000000..bc983f5 --- /dev/null +++ b/tests/library/exp-memory/notes.md @@ -0,0 +1,3 @@ +# Explicit memory library trace + +This compatibility fixture imports memory.cps with -no-std and no STRING library. Each supported C integer type produces null for zero allocation and resizing, then supports a nested allocation/resize/release. NEW storage retains 7 through REALLOC and is accepted by DELETE. MALLOC storage holds 17 and is accepted by DELETE. FREE releases NEW storage, so a subsequent DELETE throws before destruction. Negative signed-char and maximum unsigned-long-long sizes both fail allocation, confirming signed extension and unsigned range preservation. Expected values are derived directly from these assignments; human review pending. diff --git a/tests/library/exp-memory/program.cps b/tests/library/exp-memory/program.cps new file mode 100644 index 0000000..5b0eb07 --- /dev/null +++ b/tests/library/exp-memory/program.cps @@ -0,0 +1,76 @@ +INCLUDE "../../../pseudocode-lib/memory.cps" +TYPE Raw = C_TYPE("void*") +DECLARE Empty : Raw +TYPE Size0 = C_TYPE("_Bool") +TYPE Size1 = C_TYPE("char") +TYPE Size2 = C_TYPE("signed char") +TYPE Size3 = C_TYPE("unsigned char") +TYPE Size4 = C_TYPE("short") +TYPE Size5 = C_TYPE("unsigned short") +TYPE Size6 = C_TYPE("int") +TYPE Size7 = C_TYPE("unsigned int") +TYPE Size8 = C_TYPE("long") +TYPE Size9 = C_TYPE("unsigned long") +TYPE Size10 = C_TYPE("long long") +TYPE Size11 = C_TYPE("unsigned long long") +OUTPUT malloc((Size0)0) = Empty, realloc(Empty, (Size0)0) = Empty +FREE(REALLOC(MALLOC((Size0)1), (Size0)2)) +OUTPUT malloc((Size1)0) = Empty, realloc(Empty, (Size1)0) = Empty +FREE(REALLOC(MALLOC((Size1)1), (Size1)2)) +OUTPUT malloc((Size2)0) = Empty, realloc(Empty, (Size2)0) = Empty +FREE(REALLOC(MALLOC((Size2)1), (Size2)2)) +OUTPUT malloc((Size3)0) = Empty, realloc(Empty, (Size3)0) = Empty +FREE(REALLOC(MALLOC((Size3)1), (Size3)2)) +OUTPUT malloc((Size4)0) = Empty, realloc(Empty, (Size4)0) = Empty +FREE(REALLOC(MALLOC((Size4)1), (Size4)2)) +OUTPUT malloc((Size5)0) = Empty, realloc(Empty, (Size5)0) = Empty +FREE(REALLOC(MALLOC((Size5)1), (Size5)2)) +OUTPUT malloc((Size6)0) = Empty, realloc(Empty, (Size6)0) = Empty +FREE(REALLOC(MALLOC((Size6)1), (Size6)2)) +OUTPUT malloc((Size7)0) = Empty, realloc(Empty, (Size7)0) = Empty +FREE(REALLOC(MALLOC((Size7)1), (Size7)2)) +OUTPUT malloc((Size8)0) = Empty, realloc(Empty, (Size8)0) = Empty +FREE(REALLOC(MALLOC((Size8)1), (Size8)2)) +OUTPUT malloc((Size9)0) = Empty, realloc(Empty, (Size9)0) = Empty +FREE(REALLOC(MALLOC((Size9)1), (Size9)2)) +OUTPUT malloc((Size10)0) = Empty, realloc(Empty, (Size10)0) = Empty +FREE(REALLOC(MALLOC((Size10)1), (Size10)2)) +OUTPUT malloc((Size11)0) = Empty, realloc(Empty, (Size11)0) = Empty +FREE(REALLOC(MALLOC((Size11)1), (Size11)2)) +CLASS Item + Value : INTEGER +ENDCLASS +TYPE ItemPointer = ^Item +DECLARE Obj : Item +DECLARE P : ItemPointer +DECLARE Address : Raw +Obj <- NEW Item() +Obj.Value <- 7 +P <- ^Obj +Address <- REALLOC((Raw)P, 16) +P <- (ItemPointer)Address +OUTPUT P^.Value +DELETE P^ +P <- (ItemPointer)MALLOC(8) +P^.Value <- 17 +OUTPUT P^.Value +DELETE P^ +Obj <- NEW Item() +P <- ^Obj +Address <- (Raw)P +FREE(Address) +TRY + DELETE Obj +CATCH + OUTPUT 1 +ENDTRY +TRY + MALLOC((Size2)-1) +CATCH + OUTPUT 2 +ENDTRY +TRY + MALLOC((Size11)-1) +CATCH + OUTPUT 3 +ENDTRY diff --git a/tests/library/exp-string/case.json b/tests/library/exp-string/case.json index 4e37b1c..824231f 100644 --- a/tests/library/exp-string/case.json +++ b/tests/library/exp-string/case.json @@ -1 +1 @@ -{"sources":["program.cps","../../../pseudocode-lib/string.cps"],"compiler_args":["-no-std"]} +{"sources":["program.cps","../../../pseudocode-lib/std.cps","../../../pseudocode-lib/string.cps","../../../pseudocode-lib/memory.cps"],"compiler_args":["-no-std"]} diff --git a/tests/library/exp-string/program.cps b/tests/library/exp-string/program.cps index 2e45dc3..d66a01f 100644 --- a/tests/library/exp-string/program.cps +++ b/tests/library/exp-string/program.cps @@ -1,4 +1,4 @@ -INCLUDE "../../../pseudocode-lib/string.cps" +INCLUDE "../../../pseudocode-lib/std.cps" FUNCTION Echo(S : STRING) RETURNS STRING RETURN S ENDFUNCTION |
