From ad665fba735d3471c69c7fba094acd0e35659d5e Mon Sep 17 00:00:00 2001 From: Romain Goyet Date: Tue, 28 Jan 2020 18:46:40 -0500 Subject: [PATCH] [python] Add a simple test --- python/Makefile | 4 ++++ python/test/mandelbrot.cpp | 39 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 python/test/mandelbrot.cpp diff --git a/python/Makefile b/python/Makefile index dc917fab1..c8d8fa8df 100644 --- a/python/Makefile +++ b/python/Makefile @@ -180,3 +180,7 @@ $(eval $(call rule_for, \ )) $(call object_for,$(python_src)): $(BUILD_DIR)/python/port/genhdr/qstrdefs.generated.h + +tests_src += $(addprefix python/test/,\ + mandelbrot.cpp \ +) diff --git a/python/test/mandelbrot.cpp b/python/test/mandelbrot.cpp new file mode 100644 index 000000000..c84377530 --- /dev/null +++ b/python/test/mandelbrot.cpp @@ -0,0 +1,39 @@ +#include +#include +#include + + +class TestExecutionEnvironment : public MicroPython::ExecutionEnvironment { +public: + void printText(const char * text, size_t length) override; +}; + +void TestExecutionEnvironment::printText(const char * text, size_t length) { + quiz_print(text); +} + +static constexpr int k_pythonHeapSize = 16384; +static char s_pythonHeap[k_pythonHeapSize*100]; + +static const char * s_mandelbrotScript = R"(# +def mandelbrot(N_iteration): + for x in range(320): + for y in range(222): + z = complex(0,0) + c = complex(3.5*x/319-2.5, -2.5*y/221+1.25) + i = 0 + while (i < N_iteration) and abs(z) < 2: + i = i + 1 + z = z*z+c + rgb = int(255*i/N_iteration) + col = (int(rgb),int(rgb*0.75),int(rgb*0.25)) +mandelbrot(2) +print('ok') +)"; + +QUIZ_CASE(python_mandelbrot) { + MicroPython::init(s_pythonHeap, s_pythonHeap + k_pythonHeapSize); + TestExecutionEnvironment env; + env.runCode(s_mandelbrotScript); + MicroPython::deinit(); +}