summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Palatin <vpalatin@chromium.org>2018-01-30 15:09:41 +0100
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2018-02-21 06:44:12 +0000
commitde18dc5ab697e391a5318ec1620dadf3d56a7440 (patch)
tree6154dbb7980e4f878034af447b6589280c0cbd13
parentc7040bf38a2bc9b9566e9e8ddec0fed3bd15e897 (diff)
downloadchrome-ec-de18dc5ab697e391a5318ec1620dadf3d56a7440.tar.gz
test: store persistence files in RAM
On VM-based builders, the nvmem unittest was sometimes missing the 10-second deadline, likely being stuck in slow I/Os. Try to move the persistent storage files used for flash 'emulation' on host from the build directory to a RAM-backed filesystem in /dev/shm in order to mitigate this bottleneck. Store the new backing files in a path like: /dev/shm/EC_persist__mnt_host_source_src_platform_ec_build_host_nvmem_nvmem.exe_flash in order to keep the properties of the old system: subsequent runs of the same build will use the same persistent storage but 2 different trees won't mix up. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=none BUG=chromium:715011 TEST=make runtests TEST=run the following command with and without this change: 'for i in 0 1 2 3 4 5 6 7 8 9 ; do time make run-nvmem ; done' and see the average test time around 500 ms without the change and around 320 ms with it on an idle and beefy workstation. Change-Id: Ic2ff6511b81869171efc484ca805f8c0d6008595 Reviewed-on: https://chromium-review.googlesource.com/893380 Commit-Ready: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org> (cherry picked from commit 924d21d904b9f2c640ee5b0ccabcf78200456a0f) Reviewed-on: https://chromium-review.googlesource.com/928121 Commit-Queue: Vincent Palatin <vpalatin@chromium.org> Trybot-Ready: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--chip/host/persistence.c36
1 files changed, 22 insertions, 14 deletions
diff --git a/chip/host/persistence.c b/chip/host/persistence.c
index 4be2683bb1..dbd1ce812c 100644
--- a/chip/host/persistence.c
+++ b/chip/host/persistence.c
@@ -5,35 +5,43 @@
/* Persistence module for emulator */
+#include <linux/limits.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
-#define BUF_SIZE 1024
-
static void get_storage_path(char *out)
{
- char buf[BUF_SIZE];
+ char buf[PATH_MAX];
int sz;
+ char *current;
- sz = readlink("/proc/self/exe", buf, BUF_SIZE);
+ sz = readlink("/proc/self/exe", buf, PATH_MAX - 1);
buf[sz] = '\0';
- if (snprintf(out, BUF_SIZE, "%s_persist", buf) >= BUF_SIZE)
- out[BUF_SIZE - 1] = '\0';
+
+ /* replace / by underscores in the path to get the shared memory name */
+ current = strchr(buf, '/');
+ while (current) {
+ *current = '_';
+ current = strchr(current, '/');
+ }
+
+ snprintf(out, PATH_MAX - 1, "/dev/shm/EC_persist_%s", buf);
+ out[PATH_MAX - 1] = '\0';
}
FILE *get_persistent_storage(const char *tag, const char *mode)
{
- char buf[BUF_SIZE];
- char path[BUF_SIZE];
+ char buf[PATH_MAX];
+ char path[PATH_MAX];
/*
* The persistent storage with tag 'foo' for test 'bar' would
* be named 'bar_persist_foo'
*/
get_storage_path(buf);
- if (snprintf(path, BUF_SIZE, "%s_%s", buf, tag) >= BUF_SIZE)
- path[BUF_SIZE - 1] = '\0';
+ snprintf(path, PATH_MAX - 1, "%s_%s", buf, tag);
+ path[PATH_MAX - 1] = '\0';
return fopen(path, mode);
}
@@ -45,12 +53,12 @@ void release_persistent_storage(FILE *ps)
void remove_persistent_storage(const char *tag)
{
- char buf[BUF_SIZE];
- char path[BUF_SIZE];
+ char buf[PATH_MAX];
+ char path[PATH_MAX];
get_storage_path(buf);
- if (snprintf(path, BUF_SIZE, "%s_%s", buf, tag) >= BUF_SIZE)
- path[BUF_SIZE - 1] = '\0';
+ snprintf(path, PATH_MAX - 1, "%s_%s", buf, tag);
+ path[PATH_MAX - 1] = '\0';
unlink(path);
}