[python/test] Do not use such a big python heap

This commit is contained in:
Léa Saviot
2020-02-12 13:45:37 +01:00
parent 406549ff08
commit 6dced2d157
2 changed files with 7 additions and 4 deletions

View File

@@ -69,13 +69,15 @@ public:
void deinitPython();
VariableBoxController * variableBoxController() { return &m_variableBoxController; }
static constexpr int k_pythonHeapSize = 16384;
private:
/* Python delegate:
* MicroPython requires a heap. To avoid dynamic allocation, we keep a working
* buffer here and we give to controllers that load Python environment. We
* also memoize the last Python user to avoid re-initiating MicroPython when
* unneeded. */
static constexpr int k_pythonHeapSize = 16384;
char m_pythonHeap[k_pythonHeapSize];
const void * m_pythonUser;

View File

@@ -2,6 +2,7 @@
#include <assert.h>
#include <string.h>
#include <python/port/port.h>
#include <apps/code/app.h>
class TestExecutionEnvironment : public MicroPython::ExecutionEnvironment {
@@ -13,8 +14,8 @@ 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 constexpr int s_pythonHeapSize = Code::App::k_pythonHeapSize;
static char s_pythonHeap[s_pythonHeapSize];
static const char * s_mandelbrotScript = R"(#
def mandelbrot(N_iteration):
@@ -61,7 +62,7 @@ QUIZ_CASE(python_mandelbrot) {
constexpr size_t bufferSize = 500;
char buffer[bufferSize];
inlineToBeSingleInput(buffer, bufferSize, s_mandelbrotScript);
MicroPython::init(s_pythonHeap, s_pythonHeap + k_pythonHeapSize);
MicroPython::init(s_pythonHeap, s_pythonHeap + s_pythonHeapSize);
TestExecutionEnvironment env;
env.runCode(buffer);
MicroPython::deinit();