From patchwork Wed Mar 7 13:07:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anders Roxell X-Patchwork-Id: 130879 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp5160836lja; Wed, 7 Mar 2018 05:07:41 -0800 (PST) X-Google-Smtp-Source: AG47ELvEwWvNxgoLN7t6YBFtIfFqE4k2E2KBcCEiSDSS8aciIDexsm2pDDuymV2qqnEFa7b9R0ka X-Received: by 2002:a17:902:b582:: with SMTP id a2-v6mr19946313pls.353.1520428061015; Wed, 07 Mar 2018 05:07:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520428061; cv=none; d=google.com; s=arc-20160816; b=IgaP2bSv/32oT5Viph1osWV3Q1wjNgGVdja3p3jrrYV8GXA9/9runDij6yJUGRIrD6 NW4J5NT3Ks9IDAWzPmifJ/L3zokmFSGPCkpdilFbRB/xMBvO2fQtGANJsil/mRLwSJhQ fKVN7N3834YSOrltjAo0aJfUEUceGQBe4s491FPFFWFtAx/SfKMAj7AkKW1MOQRhAdWD +EkxgU21G1Oh/qQKR8cv79JW+Yqu/bzmzuQFZz2fAEm9MUyg+Wbdd2xH+uk+ZsRr8k5x CDUda5MTZfnwZLIsgBdkAcreMq8Ue3eZDmNwr8FJbyI1F8lJydJubuELmXD5wMUNMsCS IZUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=Tmqf8rxNl6II+VaQlXHXiOukHIJjjR4u659S77WwWmM=; b=tnGnzSofydcWctud+lWlrUGjMWBdwUo/b6igjy9dHn/6aH6eetVGiK9ZIQlfXXaoZ/ Lz0PWdG8n92oy1oTVZnYqyH4oyStIPo1zS2fj7sMsKNfT95UXAzUpgZcV4DZBWojrrkQ qK5p0zy3RLCmXsHX/1g/tgCZriVZbq5x+wV18ba4tfqUlAOYg4ro271MOuDnPcs86YK6 /jtwNX2ihycMABKT+WPMO2MJ2JDzCO5S+8SeGVeAuun8h1MH5Qg53YPkymAazxIZPhoU 8tyLWXtWgJRCDfpMkSsG8oak4NoNBP2WfzT77FsjMRQBoH++mwv8iTE0RIGUgT2Fm83c GgLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=axv3AJce; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k15si11426501pgr.430.2018.03.07.05.07.40; Wed, 07 Mar 2018 05:07:40 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=axv3AJce; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933270AbeCGNHh (ORCPT + 28 others); Wed, 7 Mar 2018 08:07:37 -0500 Received: from mail-lf0-f66.google.com ([209.85.215.66]:38854 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751150AbeCGNHf (ORCPT ); Wed, 7 Mar 2018 08:07:35 -0500 Received: by mail-lf0-f66.google.com with SMTP id i80-v6so3129085lfg.5 for ; Wed, 07 Mar 2018 05:07:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=Tmqf8rxNl6II+VaQlXHXiOukHIJjjR4u659S77WwWmM=; b=axv3AJce0058AEUJS9Q0+4ycfOS+6jQU9X+c5jv5Pam9+j7QpNUdRxSWYeD/tXKI89 fn6jZL14khLhIbUKEWc0oP/LqZ6Fmv6ZZGGMUG/lDTTuu4XQgVZKkZRKHuIKGqc7JoVj +7Lfp191DJfuo/DoJ2VRRpVQT5qMY8RT2rWhg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Tmqf8rxNl6II+VaQlXHXiOukHIJjjR4u659S77WwWmM=; b=V9nTlCiRw/yWqzhEaAUIhpa1ZA4ZCJ7J7ZXGvXo8mZpCedeLEBINa//J3g1A+nNiE5 Oh66dqBcSXGZrFE6Asep8EIpHiY6LqhJsOkM167oTJvjaEQYm+toGIAVC5majmFuF1ew /cDToeCwthzL5LI0BnI6pF/9lNZ7PJpPTQ4E7VKHVyrw5BW+qn8AlRfI6ZfqVjYJkXuo R7Be8MkroYg4BhcuVHzGwv1uyg9i+nDT2+yVl/B+6iSkAWVov9hWAnW3Qxjo6EEcgnun vHScaarPeF0J3oqHWEHe43gLLheUiNTIvNfvOJobmCeIvUerNPZt87GpjbLjmmtve+MW x/oQ== X-Gm-Message-State: AElRT7Ecn0ar/LHD8yrIHdoCtN/OCY8EijVDOliL0ofJcSovQ8mize0z HDp4MIpRcz4xFu72dph1xRA33A== X-Received: by 10.46.89.213 with SMTP id g82mr15958626ljf.105.1520428054185; Wed, 07 Mar 2018 05:07:34 -0800 (PST) Received: from localhost (c-2c3d70d5.07-21-73746f28.cust.bredbandsbolaget.se. [213.112.61.44]) by smtp.gmail.com with ESMTPSA id x13sm3594012ljd.6.2018.03.07.05.07.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 07 Mar 2018 05:07:33 -0800 (PST) From: Anders Roxell To: shuah@kernel.org Cc: tbird20d@gmail.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Anders Roxell Subject: [PATCH] selftests/size: rework to use main instead of _start Date: Wed, 7 Mar 2018 14:07:25 +0100 Message-Id: <20180307130725.8267-1-anders.roxell@linaro.org> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In a -ffreestanding environment without glibc, we shouldn't be able to call either getenv or printf. It seems that printf() happens to work fine, but it ends up using the glibc getenv(), which doesn't work unless we call the glibc _start() function first. Using _start() was originally meant as an optimization to reduce the memory consumption of the test program itself, in order to get a more accurate representation of the available RAM at system boot time. However, it causes more problems than it helps, especially when run from a shell script that also consumes some memory. get_size[2838]: segfault at ffffffffffffffd0 ip 000000000040538b sp 00007ffc41980668 error 5 in get_size[400000+b0000] audit: type=1701 audit(1521532923.838:4): auid=0 uid=0 gid=0 ses=2 subj=kernel pid=2838 comm=\"get_size\" exe=\"/opt/kselftests/next/size/get_size\" sig=11 res=1 get_size[2840]: segfault at ffffffffffffffd0 ip 000000000040538b sp 00007ffdace9b378 error 5 in get_size[400000+b0000] audit: type=1701 audit(1521532932.057:5): auid=0 uid=0 gid=0 ses=2 subj=kernel pid=2840 comm=\"get_size\" exe=\"/opt/kselftests/next/size/get_size\" sig=11 res=1 Rework to get_size test to use main (and printf) instead of _start. All other seftest tests uses main and not _start. Fixes: 0081901af95f ("selftests: size call ksft_print_header() to print TAP header") Signed-off-by: Anders Roxell --- tools/testing/selftests/size/Makefile | 2 +- tools/testing/selftests/size/get_size.c | 47 ++++++++++----------------------- 2 files changed, 15 insertions(+), 34 deletions(-) -- 2.11.0 diff --git a/tools/testing/selftests/size/Makefile b/tools/testing/selftests/size/Makefile index 4685b3e421fc..73932e0e7cd0 100644 --- a/tools/testing/selftests/size/Makefile +++ b/tools/testing/selftests/size/Makefile @@ -1,4 +1,4 @@ -CFLAGS := -static -ffreestanding -nostartfiles -s +CFLAGS := -static -ffreestanding -s TEST_GEN_PROGS := get_size diff --git a/tools/testing/selftests/size/get_size.c b/tools/testing/selftests/size/get_size.c index 1280b09266f0..490cf4e26eaf 100644 --- a/tools/testing/selftests/size/get_size.c +++ b/tools/testing/selftests/size/get_size.c @@ -26,13 +26,6 @@ #include #include "../kselftest.h" -#define STDOUT_FILENO 1 - -static int print(const char *s) -{ - return write(STDOUT_FILENO, s, __builtin_strlen(s)); -} - static inline char *num_to_str(unsigned long num, char *buf, int len) { unsigned int digit; @@ -49,30 +42,18 @@ static inline char *num_to_str(unsigned long num, char *buf, int len) return buf; } -static int print_num(unsigned long num) -{ - char num_buf[30]; - - return print(num_to_str(num, num_buf, sizeof(num_buf))); -} - static int print_k_value(const char *s, unsigned long num, unsigned long units) { unsigned long long temp; - int ccode; - - print(s); temp = num; temp = (temp * units)/1024; num = temp; - ccode = print_num(num); - print("\n"); - return ccode; + return printf("%s%d\n", s, num); } /* this program has no main(), as startup libraries are not used */ -void _start(void) +int main(void) { int ccode; struct sysinfo info; @@ -80,28 +61,28 @@ void _start(void) static const char *test_name = " get runtime memory use\n"; ksft_print_header(); - print("# Testing system size.\n"); + printf("# Testing system size.\n"); ccode = sysinfo(&info); if (ccode < 0) { - print("not ok 1"); - print(test_name); - print(" ---\n reason: \"could not get sysinfo\"\n ...\n"); - _exit(ccode); + printf("not ok 1"); + printf(test_name); + printf(" ---\n reason: \"could not get sysinfo\"\n ...\n"); + return 1; } - print("ok 1"); - print(test_name); + printf("ok 1"); + printf(test_name); /* ignore cache complexities for now */ used = info.totalram - info.freeram - info.bufferram; - print("# System runtime memory report (units in Kilobytes):\n"); - print(" ---\n"); + printf("# System runtime memory report (units in Kilobytes):\n"); + printf(" ---\n"); print_k_value(" Total: ", info.totalram, info.mem_unit); print_k_value(" Free: ", info.freeram, info.mem_unit); print_k_value(" Buffer: ", info.bufferram, info.mem_unit); print_k_value(" In use: ", used, info.mem_unit); - print(" ...\n"); - print("1..1\n"); + printf(" ...\n"); + printf("1..1\n"); - _exit(0); + return 0; }