From patchwork Mon Aug 18 19:12:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: gary.robertson@linaro.org X-Patchwork-Id: 35535 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f69.google.com (mail-pa0-f69.google.com [209.85.220.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 66C2B20676 for ; Mon, 18 Aug 2014 19:13:58 +0000 (UTC) Received: by mail-pa0-f69.google.com with SMTP id kx10sf46967469pab.8 for ; Mon, 18 Aug 2014 12:13:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:subject :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:errors-to:x-original-sender :x-original-authentication-results:mailing-list:content-type :content-transfer-encoding; bh=rfqc35kXvbwOXATtJH0GpmvJMFQXCjSGCoE8jzS0XjM=; b=gXazy+SCEhnJRln6qIuh7Uo0PW+7qVrTSId7Ff+l4o+W9z44e2D+v74yGJCcuwXsui +GkQIdmS4+4Rj5OaTtECMt3RKr3eZ7Il3JJp+KTEMLpWQFKuKRlGho1W51qnUP4yi0vM UZbBi6UH7dbNRBhS6K3y2fMyg1EehCkKDY3F3MH1s8wPtxm/wL8hjkUXJ73fnwxNxEqp UunQMxENvSGhPmKuM6JTH0gjMQHkb1q/Urz68iZGL2JMOm+HlIfQPSupZtL580VUkUdZ 0ATyFPhpTn6GyEiWUtWfUbXiN6WpyXQMAcx7XAYX1ZF7qSxgFynhZmNz5B+7r+Yv0tqC YTxQ== X-Gm-Message-State: ALoCoQkiI9/8EYDo8MZ6/DxpHzREnblvBvjXmUCg0aMXu5Kpx6PzhtuWdg7CNCBpTZe0bIjM/aBp X-Received: by 10.70.90.47 with SMTP id bt15mr19343227pdb.4.1408389229269; Mon, 18 Aug 2014 12:13:49 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.48.138 with SMTP id o10ls2548396qga.98.gmail; Mon, 18 Aug 2014 12:13:49 -0700 (PDT) X-Received: by 10.220.184.70 with SMTP id cj6mr26373168vcb.5.1408389228984; Mon, 18 Aug 2014 12:13:48 -0700 (PDT) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id sj4si7506428vcb.33.2014.08.18.12.13.48 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 18 Aug 2014 12:13:48 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.170 as permitted sender) client-ip=209.85.220.170; Received: by mail-vc0-f170.google.com with SMTP id lf12so6323400vcb.29 for ; Mon, 18 Aug 2014 12:13:48 -0700 (PDT) X-Received: by 10.220.15.8 with SMTP id i8mr2127339vca.45.1408389228843; Mon, 18 Aug 2014 12:13:48 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp177787vcb; Mon, 18 Aug 2014 12:13:48 -0700 (PDT) X-Received: by 10.50.57.68 with SMTP id g4mr908234igq.48.1408389228106; Mon, 18 Aug 2014 12:13:48 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id ly9si10066754icb.90.2014.08.18.12.13.47 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 18 Aug 2014 12:13:48 -0700 (PDT) Received-SPF: pass (google.com: domain of ltp-list-bounces@lists.sourceforge.net designates 216.34.181.88 as permitted sender) client-ip=216.34.181.88; Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XJSNA-0005lb-Hg; Mon, 18 Aug 2014 19:13:40 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XJSN9-0005lW-8u for ltp-list@lists.sourceforge.net; Mon, 18 Aug 2014 19:13:39 +0000 Received-SPF: pass (sog-mx-1.v43.ch3.sourceforge.com: domain of linaro.org designates 209.85.219.44 as permitted sender) client-ip=209.85.219.44; envelope-from=gary.robertson@linaro.org; helo=mail-oa0-f44.google.com; Received: from mail-oa0-f44.google.com ([209.85.219.44]) by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1XJSN7-0004Vf-68 for ltp-list@lists.sourceforge.net; Mon, 18 Aug 2014 19:13:39 +0000 Received: by mail-oa0-f44.google.com with SMTP id eb12so4439535oac.31 for ; Mon, 18 Aug 2014 12:13:27 -0700 (PDT) X-Received: by 10.60.162.71 with SMTP id xy7mr38437007oeb.33.1408389207772; Mon, 18 Aug 2014 12:13:27 -0700 (PDT) Received: from honkintosh.cybertech.lan (65-120-133-114.dia.static.qwest.net. [65.120.133.114]) by mx.google.com with ESMTPSA id oj7sm18998321obc.19.2014.08.18.12.13.23 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 18 Aug 2014 12:13:26 -0700 (PDT) From: "Gary S. Robertson" To: ltp-list@lists.sourceforge.net Date: Mon, 18 Aug 2014 14:12:56 -0500 Message-Id: <1408389176-20141-1-git-send-email-gary.robertson@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Spam-Score: -1.5 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record X-Headers-End: 1XJSN7-0004Vf-68 Subject: [LTP] [PATCH] Realtime tests: Ensure mutexes initialized statically X-BeenThere: ltp-list@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-list-bounces@lists.sourceforge.net X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: gary.robertson@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.170 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: "Gary S. Robertson" In a cross-development environment, build-time configuration may result in the lib/librttest function 'init_pi_mutex' being built as an empty function even though priority inheritence is supported on the test target system upon which the test code will execute. (NOTE that several pi-tests depending on 'init-pi-mutex' still build and execute even though this function as compiled performs no inititalization.) This leaves mutexes un-initialized if they rely on this function for proper initialization... so they should be at least initialized to default values when they are defined, in order to prevent possible program faults resulting from attempts to use them in an un-initialized state. With this patch, the pi-tests run to completion and return failure results if the conditionally-compiled code is missing in 'init-pi-mutex'. Signed-off-by: Gary S. Robertson --- .../realtime/func/async_handler/async_handler.c | 2 +- .../func/async_handler/async_handler_tsc.c | 2 +- testcases/realtime/func/pi-tests/testpi-1.c | 2 +- testcases/realtime/func/pi-tests/testpi-2.c | 2 +- testcases/realtime/func/pi-tests/testpi-4.c | 20 +++++++------------- testcases/realtime/func/pi-tests/testpi-7.c | 4 ++-- testcases/realtime/func/pi_perf/pi_perf.c | 2 +- testcases/realtime/func/prio-wake/prio-wake.c | 2 +- .../realtime/perf/latency/pthread_cond_many.c | 2 +- .../realtime/stress/pi-tests/lookup_pi_state.c | 6 +++--- 10 files changed, 19 insertions(+), 25 deletions(-) diff --git a/testcases/realtime/func/async_handler/async_handler.c b/testcases/realtime/func/async_handler/async_handler.c index 3c1bfdd..e61fa71 100644 --- a/testcases/realtime/func/async_handler/async_handler.c +++ b/testcases/realtime/func/async_handler/async_handler.c @@ -60,7 +60,7 @@ static int iterations = 0; atomic_t step; pthread_cond_t cond = PTHREAD_COND_INITIALIZER; -pthread_mutex_t mutex; +pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static int ret = 0; diff --git a/testcases/realtime/func/async_handler/async_handler_tsc.c b/testcases/realtime/func/async_handler/async_handler_tsc.c index c51a3b4..bb554b9 100644 --- a/testcases/realtime/func/async_handler/async_handler_tsc.c +++ b/testcases/realtime/func/async_handler/async_handler_tsc.c @@ -68,7 +68,7 @@ int over_30 = 0; atomic_t step; pthread_cond_t cond = PTHREAD_COND_INITIALIZER; -pthread_mutex_t mutex; +pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; void usage(void) { diff --git a/testcases/realtime/func/pi-tests/testpi-1.c b/testcases/realtime/func/pi-tests/testpi-1.c index 3dbe292..4adcf5a 100644 --- a/testcases/realtime/func/pi-tests/testpi-1.c +++ b/testcases/realtime/func/pi-tests/testpi-1.c @@ -74,7 +74,7 @@ int gettid(void) } typedef void *(*entrypoint_t) (void *); -pthread_mutex_t glob_mutex; +pthread_mutex_t glob_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t cond_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t cond_var = PTHREAD_COND_INITIALIZER; diff --git a/testcases/realtime/func/pi-tests/testpi-2.c b/testcases/realtime/func/pi-tests/testpi-2.c index 3f7185e..b22935f 100644 --- a/testcases/realtime/func/pi-tests/testpi-2.c +++ b/testcases/realtime/func/pi-tests/testpi-2.c @@ -76,7 +76,7 @@ int gettid(void) } typedef void *(*entrypoint_t) (void *); -pthread_mutex_t glob_mutex; +pthread_mutex_t glob_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t cond_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t cond_var = PTHREAD_COND_INITIALIZER; diff --git a/testcases/realtime/func/pi-tests/testpi-4.c b/testcases/realtime/func/pi-tests/testpi-4.c index e9e0ed6..7c44111 100644 --- a/testcases/realtime/func/pi-tests/testpi-4.c +++ b/testcases/realtime/func/pi-tests/testpi-4.c @@ -75,7 +75,7 @@ int gettid(void) } typedef void *(*entrypoint_t) (void *); -pthread_mutex_t *glob_mutex; +pthread_mutex_t glob_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t cond_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t cond_var = PTHREAD_COND_INITIALIZER; @@ -86,7 +86,7 @@ void *func_nonrt(void *arg) printf("Thread %d started running with priority %d\n", tid, pthr->priority); - pthread_mutex_lock(glob_mutex); + pthread_mutex_lock(&glob_mutex); printf("Thread %d at start pthread pol %d pri %d - Got global lock\n", tid, pthr->policy, pthr->priority); @@ -106,7 +106,7 @@ void *func_nonrt(void *arg) } busy_work_ms(1); } - pthread_mutex_unlock(glob_mutex); + pthread_mutex_unlock(&glob_mutex); return NULL; } @@ -117,7 +117,7 @@ void *func_rt(void *arg) printf("Thread %d started running with prio %d\n", tid, pthr->priority); pthread_barrier_wait(&barrier); - pthread_mutex_lock(glob_mutex); + pthread_mutex_lock(&glob_mutex); printf("Thread %d at start pthread pol %d pri %d - Got global lock\n", tid, pthr->policy, pthr->priority); @@ -134,7 +134,7 @@ void *func_rt(void *arg) } busy_work_ms(1); } - pthread_mutex_unlock(glob_mutex); + pthread_mutex_unlock(&glob_mutex); return NULL; } @@ -198,14 +198,8 @@ int main(int argc, char *argv[]) printf("Start %s\n", argv[0]); - glob_mutex = malloc(sizeof(pthread_mutex_t)); - if (glob_mutex == NULL) { - printf("Malloc failed\n"); - exit(errno); - } - if (!nopi) - init_pi_mutex(glob_mutex); + init_pi_mutex(&glob_mutex); create_other_thread(func_nonrt, NULL); create_rr_thread(func_rt, NULL, 20); @@ -217,7 +211,7 @@ int main(int argc, char *argv[]) join_threads(); printf("Done\n"); - pthread_mutex_destroy(glob_mutex); + pthread_mutex_destroy(&glob_mutex); pthread_mutex_destroy(&cond_mutex); pthread_cond_destroy(&cond_var); diff --git a/testcases/realtime/func/pi-tests/testpi-7.c b/testcases/realtime/func/pi-tests/testpi-7.c index e9e286d..ce222a3 100644 --- a/testcases/realtime/func/pi-tests/testpi-7.c +++ b/testcases/realtime/func/pi-tests/testpi-7.c @@ -55,7 +55,7 @@ static int use_flag_mutex; static int max_delay_us; static int max_drop2grab_us; -static pthread_mutex_t pi_mutex; +static pthread_mutex_t pi_mutex = PTHREAD_MUTEX_INITIALIZER; // flagging details typedef enum { @@ -69,7 +69,7 @@ typedef enum { static volatile phase_t phase_flag = END_OF_CYCLE; -static pthread_mutex_t flag_mutex; +static pthread_mutex_t flag_mutex = PTHREAD_MUTEX_INITIALIZER; int med_threads = 0; long iterations = ITERATIONS; diff --git a/testcases/realtime/func/pi_perf/pi_perf.c b/testcases/realtime/func/pi_perf/pi_perf.c index daa7643..8f370b7 100644 --- a/testcases/realtime/func/pi_perf/pi_perf.c +++ b/testcases/realtime/func/pi_perf/pi_perf.c @@ -63,7 +63,7 @@ #define THRESHOLD 200 /* microseconds */ pthread_barrier_t bar1, bar2; -pthread_mutex_t lock; +pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; static int end = 0; diff --git a/testcases/realtime/func/prio-wake/prio-wake.c b/testcases/realtime/func/prio-wake/prio-wake.c index 18c0405..f8c8de5 100644 --- a/testcases/realtime/func/prio-wake/prio-wake.c +++ b/testcases/realtime/func/prio-wake/prio-wake.c @@ -60,7 +60,7 @@ volatile int running_threads = 0; static int rt_threads = 0; static int locked_broadcast = 1; static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; -static pthread_mutex_t mutex; +static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static volatile nsec_t beginrun; static int ret = 0; diff --git a/testcases/realtime/perf/latency/pthread_cond_many.c b/testcases/realtime/perf/latency/pthread_cond_many.c index 1d39100..4146241 100644 --- a/testcases/realtime/perf/latency/pthread_cond_many.c +++ b/testcases/realtime/perf/latency/pthread_cond_many.c @@ -47,7 +47,7 @@ #include #include #define PASS_US 100 -pthread_mutex_t child_mutex; +pthread_mutex_t child_mutex = PTHREAD_MUTEX_INITIALIZER; volatile int *child_waiting = NULL; double endtime; pthread_cond_t *condlist = NULL; diff --git a/testcases/realtime/stress/pi-tests/lookup_pi_state.c b/testcases/realtime/stress/pi-tests/lookup_pi_state.c index d1575dc..5869c99 100644 --- a/testcases/realtime/stress/pi-tests/lookup_pi_state.c +++ b/testcases/realtime/stress/pi-tests/lookup_pi_state.c @@ -39,9 +39,9 @@ #define NUM_SLAVES 20 #define SLAVE_PRIO 89 -pthread_mutex_t MM; -pthread_mutex_t MS; -pthread_mutex_t MT; +pthread_mutex_t MM = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t MS = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t MT = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t CM; pthread_cond_t CS; pthread_cond_t CT;