소스 검색

bindings: add SQLite open/exec/close smoke test

Eric Streit 1 일 전
부모
커밋
d3be70cc90
6개의 변경된 파일과 130개의 추가작업 그리고 1개의 파일을 삭제
  1. 2 1
      README.md
  2. 1 0
      bindings/sqlite3/.gitignore
  3. 41 0
      bindings/sqlite3/README.md
  4. 23 0
      bindings/sqlite3/SQLite.def
  5. 30 0
      bindings/sqlite3/run.sh
  6. 33 0
      bindings/sqlite3/tests/SQLiteSmoke.mod

+ 2 - 1
README.md

@@ -86,7 +86,8 @@ compiler/tests/    t_*.mod (check/reject/run) + showcase<N>.mod tours
 compiler/gen_ssa/  build outputs (gitignored)
 runtime/syslib/    shared runtime (SysShim, FileIO, SysIO, …)
 lib/{pim,iso,common,gm2}/ opt-in dialect libraries
-tools/             syntax helpers + v3-corpus (coverage harness)
+tools/             syntax helpers + M2make (build-order tool) + corpus
+bindings/          optional C bindings (first SQLite smoke test)
 bootstrap/         stage1/2/3 + fixpoint.sh (self-hosting proof)
 vendor/            qbe toolchain pin
 docs/              STATUS.md, plan.md, plan-*.md, analysis_*.md, summary_*.md

+ 1 - 0
bindings/sqlite3/.gitignore

@@ -0,0 +1 @@
+*.LST

+ 41 - 0
bindings/sqlite3/README.md

@@ -0,0 +1,41 @@
+# SQLite binding (first slice)
+
+This is the first end-to-end V3 C binding test, not a replacement for
+the full `m2SQLITE` binding.
+
+Current surface:
+
+```modula2
+sqlite3_open
+sqlite3_exec
+sqlite3_close
+SQLiteOk
+```
+
+The smoke test opens an in-memory database, creates a table, inserts a
+row, and closes the handle.
+
+## Build/run
+
+```sh
+./run.sh
+```
+
+The script uses `pkg-config --libs sqlite3` when available; otherwise it
+links the versioned runtime library directly:
+
+```text
+/usr/lib/x86_64-linux-gnu/libsqlite3.so.0
+```
+
+That fallback matters on systems with the SQLite runtime installed but
+without `libsqlite3-dev`.
+
+## Notes
+
+- `sqlite3_open` and `sqlite3_exec` exercise the C string ABI.
+- `VAR db : ADDRESS` exercises opaque C handles.
+- The smoke test uses no callback; callback bindings come after the
+  generic SQLite callback ABI is designed.
+- The full `m2SQLITE` definition remains the source for later API
+  coverage.

+ 23 - 0
bindings/sqlite3/SQLite.def

@@ -0,0 +1,23 @@
+DEFINITION MODULE FOR "C" SQLite;
+(* Minimal first SQLite binding: open an in-memory database, execute SQL,
+   and close it.  The full binding stays in m2SQLITE for later porting. *)
+
+FROM SYSTEM IMPORT ADDRESS;
+
+EXPORT UNQUALIFIED
+  SQLiteOk,
+  sqlite3_open,
+  sqlite3_exec,
+  sqlite3_close;
+
+CONST
+  SQLiteOk = 0;
+
+PROCEDURE sqlite3_open (filename : ARRAY OF CHAR;
+                        VAR db : ADDRESS) : INTEGER;
+PROCEDURE sqlite3_exec (db : ADDRESS;
+                        sql : ARRAY OF CHAR;
+                        callback, arg, errmsg : ADDRESS) : INTEGER;
+PROCEDURE sqlite3_close (db : ADDRESS) : INTEGER;
+
+END SQLite.

+ 30 - 0
bindings/sqlite3/run.sh

@@ -0,0 +1,30 @@
+#!/bin/sh
+# Minimal SQLite binding smoke test.
+set -e
+cd "$(dirname "$0")"
+ROOT="$(cd ../.. && pwd)"
+M2MAKE="$ROOT/tools/m2make/b_v3/M2make"
+if [ ! -x "$M2MAKE" ]; then
+  echo "missing $M2MAKE; run tools/m2make/build_m2.sh" >&2
+  exit 1
+fi
+SQLITE_LIBS="$(pkg-config --libs sqlite3 2>/dev/null || true)"
+if [ -z "$SQLITE_LIBS" ]; then
+  # Runtime-only installations often have no .pc/header; use the
+  # versioned shared object directly.
+  SQLITE_LIBS="/usr/lib/x86_64-linux-gnu/libsqlite3.so.0"
+fi
+OUT="${TMPDIR:-/tmp}/m2-sqlite-smoke"
+"$M2MAKE" -c m2 \
+  --m2bin "$ROOT/compiler/M2" \
+  --shim "$ROOT/runtime/syslib/shim.c" \
+  --lib "$SQLITE_LIBS" \
+  -I "$ROOT/bindings/sqlite3" \
+  -o "$OUT" \
+  tests/SQLiteSmoke.mod
+set +e
+"$OUT"
+rc=$?
+set -e
+if [ "$rc" = 42 ]; then exit 0; fi
+exit 1

+ 33 - 0
bindings/sqlite3/tests/SQLiteSmoke.mod

@@ -0,0 +1,33 @@
+MODULE SQLiteSmoke;
+(* First end-to-end SQLite binding test: :memory: open/exec/close. *)
+
+FROM SYSTEM IMPORT ADDRESS;
+FROM SQLite IMPORT SQLiteOk, sqlite3_open, sqlite3_exec, sqlite3_close;
+
+VAR
+  ExitCode : INTEGER;
+  db : ADDRESS;
+  rc : INTEGER;
+
+BEGIN
+  db := NIL;
+  rc := sqlite3_open(":memory:", db);
+  IF (rc = SQLiteOk) AND (db # NIL) THEN
+    rc := sqlite3_exec(db, "CREATE TABLE t(x INTEGER);",
+                       NIL, NIL, NIL);
+    IF rc = SQLiteOk THEN
+      rc := sqlite3_exec(db, "INSERT INTO t VALUES (42);",
+                         NIL, NIL, NIL)
+    END
+  END;
+  IF db # NIL THEN
+    IF sqlite3_close(db) # SQLiteOk THEN
+      rc := 1
+    END
+  END;
+  IF rc = SQLiteOk THEN
+    ExitCode := 42
+  ELSE
+    ExitCode := 1
+  END
+END SQLiteSmoke.