From b0a15aa73540f82ef47c9492af7ce196d1b1a6e9 Mon Sep 17 00:00:00 2001
From: Damien George <damien.p.george@gmail.com>
Date: Fri, 14 Oct 2016 00:08:19 +1100
Subject: [PATCH] qemu-arm: Enable lots of extmods and enable tests for them.

The qemu-arm port is used for testing of ARM Thumb architecture on a
desktop so should have many features enabled.
---
 qemu-arm/Makefile         |  9 +++++++++
 qemu-arm/memory.h         |  2 ++
 qemu-arm/mpconfigport.h   | 11 ++++++++++-
 qemu-arm/mphalport.h      |  3 ++-
 tools/tinytest-codegen.py | 11 +++++++++--
 5 files changed, 32 insertions(+), 4 deletions(-)
 create mode 100644 qemu-arm/memory.h

diff --git a/qemu-arm/Makefile b/qemu-arm/Makefile
index 31ba6baa2..6a25eb931 100644
--- a/qemu-arm/Makefile
+++ b/qemu-arm/Makefile
@@ -40,19 +40,28 @@ SRC_C = \
 SRC_TEST_C = \
 	test_main.c \
 
+STM_SRC_C = $(addprefix stmhal/,\
+	pybstdio.c \
+	)
+
 SRC_S = \
 
 OBJ =
 OBJ += $(PY_O)
 OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
 OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
+OBJ += $(addprefix $(BUILD)/, $(STM_SRC_C:.c=.o))
 
 OBJ_TEST =
 OBJ_TEST += $(PY_O)
 OBJ_TEST += $(addprefix $(BUILD)/, $(SRC_TEST_C:.c=.o))
 OBJ_TEST += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
+OBJ_TEST += $(addprefix $(BUILD)/, $(STM_SRC_C:.c=.o))
 OBJ_TEST += $(BUILD)/tinytest.o
 
+# List of sources for qstr extraction
+SRC_QSTR += $(SRC_C) $(SRC_TEST_C) $(STM_SRC_C)
+
 all: run
 
 run: $(BUILD)/firmware.elf
diff --git a/qemu-arm/memory.h b/qemu-arm/memory.h
new file mode 100644
index 000000000..f3777b0e3
--- /dev/null
+++ b/qemu-arm/memory.h
@@ -0,0 +1,2 @@
+// this is needed for extmod/crypto-algorithms/sha256.c
+#include <string.h>
diff --git a/qemu-arm/mpconfigport.h b/qemu-arm/mpconfigport.h
index 1f23148c2..b8806405b 100644
--- a/qemu-arm/mpconfigport.h
+++ b/qemu-arm/mpconfigport.h
@@ -20,9 +20,18 @@
 #define MICROPY_PY_ARRAY_SLICE_ASSIGN (1)
 #define MICROPY_PY_BUILTINS_FROZENSET (1)
 #define MICROPY_PY_BUILTINS_MEMORYVIEW (1)
-#define MICROPY_PY_IO               (0)
+#define MICROPY_PY_IO               (1)
 #define MICROPY_PY_SYS_EXIT         (1)
 #define MICROPY_PY_SYS_MAXSIZE      (1)
+#define MICROPY_PY_UERRNO           (1)
+#define MICROPY_PY_UBINASCII        (1)
+#define MICROPY_PY_URANDOM          (1)
+#define MICROPY_PY_UCTYPES          (1)
+#define MICROPY_PY_UZLIB            (1)
+#define MICROPY_PY_UJSON            (1)
+#define MICROPY_PY_URE              (1)
+#define MICROPY_PY_UHEAPQ           (1)
+#define MICROPY_PY_UHASHLIB         (1)
 #define MICROPY_USE_INTERNAL_PRINTF (0)
 
 // type definitions for the specific machine
diff --git a/qemu-arm/mphalport.h b/qemu-arm/mphalport.h
index 4bd8276f3..d996402ae 100644
--- a/qemu-arm/mphalport.h
+++ b/qemu-arm/mphalport.h
@@ -1 +1,2 @@
-// empty file
+#define mp_hal_stdin_rx_chr() (0)
+#define mp_hal_stdout_tx_strn_cooked(s, l) write(1, (s), (l))
diff --git a/tools/tinytest-codegen.py b/tools/tinytest-codegen.py
index 091c1b065..bab937135 100755
--- a/tools/tinytest-codegen.py
+++ b/tools/tinytest-codegen.py
@@ -46,8 +46,15 @@ testgroup_member = (
 
 ## XXX: may be we could have `--without <groups>` argument...
 # currently these tests are selected because they pass on qemu-arm
-test_dirs = ('basics', 'micropython', 'inlineasm') # 'float', 'import', 'io', 'misc')
-exclude_tests = ('inlineasm/asmfpaddsub.py', 'inlineasm/asmfpcmp.py', 'inlineasm/asmfpldrstr.py', 'inlineasm/asmfpmuldiv.py', 'inlineasm/asmfpsqrt.py',)
+test_dirs = ('basics', 'micropython', 'extmod', 'inlineasm') # 'float', 'import', 'io', 'misc')
+exclude_tests = (
+    'inlineasm/asmfpaddsub.py', 'inlineasm/asmfpcmp.py', 'inlineasm/asmfpldrstr.py', 'inlineasm/asmfpmuldiv.py', 'inlineasm/asmfpsqrt.py',
+    'extmod/time_ms_us.py',
+    'extmod/ujson_dumps_float.py', 'extmod/ujson_loads_float.py',
+    'extmod/uctypes_native_float.py', 'extmod/uctypes_le_float.py',
+    'extmod/machine_pinbase.py', 'extmod/machine_pulse.py',
+    'extmod/vfs_fat_ramdisk.py',
+)
 
 output = []
 
-- 
GitLab