Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C029EC001DE for ; Sun, 13 Aug 2023 14:30:03 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6B106869A4; Sun, 13 Aug 2023 16:27:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="gWTgp2K0"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1A5708698E; Sun, 13 Aug 2023 16:27:41 +0200 (CEST) Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id CB1D086996 for ; Sun, 13 Aug 2023 16:27:38 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x130.google.com with SMTP id e9e14a558f8ab-349974537f5so14729245ab.2 for ; Sun, 13 Aug 2023 07:27:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1691936857; x=1692541657; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=m06iEtBOEiqWun+RHbuTQw5X336dE5Vtkyzxkrzp1xo=; b=gWTgp2K0td8F2xI5seGj+qgILHnavYiI5/1bqxnZLxKFqzNs/KKTM27sB1qSHNRmck LiFOHbephCIOdZayI8Sp4aubrX+KIizJEuF9iul7uqqS6pUkiyNtC7rS+OaYHnqkUEPP /gcIhX/nPqYZ3czt7EEIGDS6suBjOSrT+GV58= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691936857; x=1692541657; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=m06iEtBOEiqWun+RHbuTQw5X336dE5Vtkyzxkrzp1xo=; b=JEIJHvKLlktuZOZ3rnhUrLlz/BAvsrGu8UMMBNBIEXLSCDkAcgQ39tZVRI+B7bFfJS Q0ZemKGLXDrUf4l86d6Y3IOKpn5FxNEbiJj+kaYHjECy/HD8Rz8jXySLV1/JMcjPD4vx T/pBOHYPGYys9VK9KfjcW8Z/C9xP6VS7YC8IXk1mEVtzQu/uF4KWj5YY/cSc6WPKQYC5 ljqaDK/wDj/8xY0V/stTg1dnW42W0KC2nzvJlAqYrJE6Css8ayMANdRwecXGv+lvjbQG jbeaezAVgzSD40oE5Eiq4e9bf33ZIZQ2PrOU3Y0uJQAAvs7Iyo62thn/i4TX8V8ud2o2 wR2g== X-Gm-Message-State: AOJu0Yw4VXlT7lk67/rjbOSlaS+MNvqzkKgmGYaEpStnjRrix1mt21fB Dq7/DcsZYjPnvR29rqsddlaMz+sSv4oaRCYZOps= X-Google-Smtp-Source: AGHT+IEqb8Xl19Ws+zX+RgWBTot+vHdUdThVib+I65GgsfJGMJU66R4pJ+OusYGgI4106sf9C43ITQ== X-Received: by 2002:a05:6e02:b2a:b0:349:3896:d931 with SMTP id e10-20020a056e020b2a00b003493896d931mr12241232ilu.18.1691936857559; Sun, 13 Aug 2023 07:27:37 -0700 (PDT) Received: from sjg1.lan (c-73-14-173-85.hsd1.co.comcast.net. [73.14.173.85]) by smtp.gmail.com with ESMTPSA id w7-20020a02cf87000000b00430cf006d9bsm2280952jar.30.2023.08.13.07.27.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Aug 2023 07:27:37 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Heinrich Schuchardt , Rasmus Villemoes Subject: [PATCH 15/24] sandbox: Add a way to access persistent test files Date: Sun, 13 Aug 2023 08:26:43 -0600 Message-ID: <20230813142708.361456-16-sjg@chromium.org> X-Mailer: git-send-email 2.41.0.640.ga95def55d0-goog In-Reply-To: <20230813142708.361456-1-sjg@chromium.org> References: <20230813142708.361456-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Some pytests create files in the persistent-data directory. It is useful to be able to access these files in C tests. Add a function which can locate a file given its leaf name, using the environment variable set up in test/py/conftest.py Signed-off-by: Simon Glass --- arch/sandbox/cpu/os.c | 24 ++++++++++++++++++++++++ include/os.h | 10 ++++++++++ 2 files changed, 34 insertions(+) diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 9e93a0fa571f..85d0d6a17035 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -258,6 +258,30 @@ int os_unmap(void *buf, int size) return 0; } +int os_persistent_file(char *buf, int maxsize, const char *fname) +{ + const char *dirname = getenv("U_BOOT_PERSISTENT_DATA_DIR"); + char *ptr; + int len; + + len = strlen(fname) + (dirname ? strlen(dirname) + 1 : 0) + 1; + if (len > maxsize) + return -ENOSPC; + + ptr = buf; + if (dirname) { + strcpy(ptr, dirname); + ptr += strlen(dirname); + *ptr++ = '/'; + } + strcpy(ptr, fname); + + if (access(buf, F_OK) == -1) + return -ENOENT; + + return 0; +} + /* Restore tty state when we exit */ static struct termios orig_term; static bool term_setup; diff --git a/include/os.h b/include/os.h index 968412b0a822..fc8a1b15cbf0 100644 --- a/include/os.h +++ b/include/os.h @@ -98,6 +98,16 @@ int os_close(int fd); */ int os_unlink(const char *pathname); +/** os_persistent_fname() - Find the path to a test file + * + * @buf: Buffer to hold path + * @maxsize: Maximum size of buffer + * @fname: Leaf filename to find + * Returns: 0 on success, -ENOENT if file is not found, -ENOSPC if the buffer is + * too small + */ +int os_persistent_file(char *buf, int maxsize, const char *fname); + /** * os_exit() - access to the OS exit() system call * -- 2.41.0.640.ga95def55d0-goog