tests: mem_protest: workaround aggressive optimization

We have some static variables var, zeroed_var and bss_var
in mem_partition.c and we only assert the value of them in
the same file, so the compiler may pre-calculate it in compile
stage, it's fine usually.
But for variable zeroed_var (= 20420), we force to put it in bss
section in link stage, the value will change in bss clean stage, so
we will get a wrong result.
Let's add volatile for these variables to disable pre-calculation.

Signed-off-by: Watson Zeng <zhiwei@synopsys.com>
This commit is contained in:
Watson Zeng 2021-06-28 11:16:07 +08:00 committed by Anas Nashif
commit e451bf44fe

View file

@ -7,9 +7,12 @@
#include <kernel.h>
#include "mem_protect.h"
static K_APP_DMEM(ztest_mem_partition) int var = 1356;
static K_APP_BMEM(ztest_mem_partition) int zeroed_var = 20420;
static K_APP_BMEM(ztest_mem_partition) int bss_var;
/* Add volatile to disable pre-calculation in compile stage in some
* toolchain, such as arcmwdt toolchain.
*/
static volatile K_APP_DMEM(ztest_mem_partition) int var = 1356;
static volatile K_APP_BMEM(ztest_mem_partition) int zeroed_var = 20420;
static volatile K_APP_BMEM(ztest_mem_partition) int bss_var;
/**
* @brief Test assigning global data and BSS variables to memory partitions