From patchwork Wed Feb 17 12:11:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 62100 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp2243236lbl; Wed, 17 Feb 2016 04:11:55 -0800 (PST) X-Received: by 10.55.79.5 with SMTP id d5mr1362149qkb.30.1455711115609; Wed, 17 Feb 2016 04:11:55 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id d69si945138qhc.98.2016.02.17.04.11.55; Wed, 17 Feb 2016 04:11:55 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id E3E03617CF; Wed, 17 Feb 2016 12:11:54 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=H+h7sFpk; dkim-adsp=none (unprotected policy); dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 71E5261794; Wed, 17 Feb 2016 12:11:51 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 0481661794; Wed, 17 Feb 2016 12:11:49 +0000 (UTC) Received: from mail-lf0-f50.google.com (mail-lf0-f50.google.com [209.85.215.50]) by lists.linaro.org (Postfix) with ESMTPS id A70F16178F for ; Wed, 17 Feb 2016 12:11:47 +0000 (UTC) Received: by mail-lf0-f50.google.com with SMTP id j78so9382478lfb.1 for ; Wed, 17 Feb 2016 04:11:47 -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=HHp5SLMdMyGyzU+B2Oga8F6WVvTHmD/CUK6JS0CwAKw=; b=H+h7sFpkDjdKYIpEbdnoaZjWfQDBtSm3ScjOAm4/IwYAReRz/zKRanscudheYhSoJ9 hO4zITU0YXrv+aLF07JjQU2IRfpc+HDiT+ttY/M9HxW9E4VihBVRZ7WNXund2qFH4kKU AGR7h6IEB6dg8Ygk/el3uN25Gbsh2PNSagxvA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=HHp5SLMdMyGyzU+B2Oga8F6WVvTHmD/CUK6JS0CwAKw=; b=j15yBu7rlegSQ6vE3etFQ+r6i1cD14MuFGjodvEgG3F+FJLi04y14ulT/20T1ztXKo KQ49eqmbvPi/IdmhzIEXM/ackxN4Z6YzoigAdto3Ycz0/ySBn+0siiSLVmnDpm28Q3gv etOxEDO9oTAF5FCs3Ot73B088/im1+GsLXByUu2aV4ImWPq6Bgg/Y6hYFt6MnBChhHf/ lYtkNHtl7oCSctIMdGBOnNe/UYT9iDOpBAwtxf4F+5V0Y0GwGjd8IRkha0waOy1tffmj MxlZuraxsDly1V9hSOQo7paB5KSdoEiR8hQn+vDiukOsXYsc2sQ3poJLqNN9HKbes3Y4 9D8Q== X-Gm-Message-State: AG10YOTBbP1sZFnYq1+Cd/3qLPuf/F8EY25SJEzPWPusSVO57tVlkgaysT08KeCSZoxU+zAqm/Y= X-Received: by 10.25.43.148 with SMTP id r142mr586246lfr.103.1455711105991; Wed, 17 Feb 2016 04:11:45 -0800 (PST) Received: from localhost.localdomain (ppp91-76-173-134.pppoe.mtu-net.ru. [91.76.173.134]) by smtp.gmail.com with ESMTPSA id y3sm161808lbk.40.2016.02.17.04.11.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 Feb 2016 04:11:45 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Wed, 17 Feb 2016 15:11:41 +0300 Message-Id: <1455711101-24345-1-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.7.1.250.gff4ea60 X-Topics: patch Subject: [lng-odp] [PATCH] validation: print backtrace on segfault and other related signals X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" If any test got segmentation fault it's better to print something useful for debug. That function is based on example code for TM. I hope it will help to see fails in CI where is not clear how to get core files. Signed-off-by: Maxim Uvarov --- test/validation/common/odp_cunit_common.c | 67 +++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/test/validation/common/odp_cunit_common.c b/test/validation/common/odp_cunit_common.c index dbd8229..602a508 100644 --- a/test/validation/common/odp_cunit_common.c +++ b/test/validation/common/odp_cunit_common.c @@ -4,10 +4,19 @@ * SPDX-License-Identifier: BSD-3-Clause */ +#include #include +#include +#include +#include +#include +#include +#include + #include #include #include + /* Globals */ static odph_linux_pthread_t thread_tbl[MAX_WORKERS]; @@ -23,6 +32,7 @@ static struct { } global_init_term = {tests_global_init, tests_global_term}; static odp_suiteinfo_t *global_testsuites; +static odp_spinlock_t print_lock; /** create test thread */ int odp_cunit_thread_create(void *func_ptr(void *), pthrd_arg *arg) @@ -115,6 +125,61 @@ static odp_testinfo_t *cunit_get_test_info(odp_suiteinfo_t *sinfo, return NULL; } +static void fault_handler(int signal) +{ + size_t num_stack_frames; + const char *signal_name; + void *bt_array[128]; + sigset_t sigset; + + /* disable all signals */ + sigfillset(&sigset); + sigprocmask(SIG_BLOCK, &sigset, NULL); + + switch (signal) { + case SIGILL: + signal_name = "SIGILL"; break; + case SIGFPE: + signal_name = "SIGFPE"; break; + case SIGSEGV: + signal_name = "SIGSEGV"; break; + case SIGTERM: + signal_name = "SIGTERM"; break; + case SIGBUS: + signal_name = "SIGBUS"; break; + default: + signal_name = "UNKNOWN"; break; + } + + odp_spinlock_lock(&print_lock); + num_stack_frames = backtrace(bt_array, 100); + printf("\nThread %d terminated with signal=%u (%s)\n", + odp_thread_id(), signal, signal_name); + backtrace_symbols_fd(bt_array, num_stack_frames, fileno(stderr)); + fflush(NULL); + sync(); + odp_spinlock_unlock(&print_lock); + + CU_ASSERT_FATAL(0); +} + +static void register_fault_handler(void) +{ + struct sigaction signal_action; + + odp_spinlock_init(&print_lock); + + memset(&signal_action, 0, sizeof(signal_action)); + signal_action.sa_handler = fault_handler; + sigfillset(&signal_action.sa_mask); + + sigaction(SIGILL, &signal_action, NULL); + sigaction(SIGFPE, &signal_action, NULL); + sigaction(SIGSEGV, &signal_action, NULL); + sigaction(SIGTERM, &signal_action, NULL); + sigaction(SIGBUS, &signal_action, NULL); +} + /* A wrapper for the suite's init function. This is done to allow for a * potential runtime check to determine whether each test in the suite * is active (enabled by using ODP_TEST_INFO_CONDITIONAL()). If present, @@ -328,6 +393,8 @@ int odp_cunit_register(odp_suiteinfo_t testsuites[]) CU_set_error_action(CUEA_ABORT); + register_fault_handler(); + CU_initialize_registry(); global_testsuites = testsuites; cunit_register_suites(testsuites);