"Fossies" - the Fresh Open Source Software Archive

Member "stress-ng-0.09.56/stress-personality.c" (15 Mar 2019, 2536 Bytes) of package /linux/privat/stress-ng-0.09.56.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "stress-personality.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 0.09.49_vs_0.09.50.

    1 /*
    2  * Copyright (C) 2013-2019 Canonical, Ltd.
    3  *
    4  * This program is free software; you can redistribute it and/or
    5  * modify it under the terms of the GNU General Public License
    6  * as published by the Free Software Foundation; either version 2
    7  * of the License, or (at your option) any later version.
    8  *
    9  * This program is distributed in the hope that it will be useful,
   10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12  * GNU General Public License for more details.
   13  *
   14  * You should have received a copy of the GNU General Public License
   15  * along with this program; if not, write to the Free Software
   16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
   17  *
   18  * This code is a complete clean re-write of the stress tool by
   19  * Colin Ian King <colin.king@canonical.com> and attempts to be
   20  * backwardly compatible with the stress tool by Amos Waterland
   21  * <apw@rossby.metr.ou.edu> but has more stress tests and more
   22  * functionality.
   23  *
   24  */
   25 #include "stress-ng.h"
   26 
   27 #if defined(HAVE_PERSONALITY)
   28 
   29 /* Personalities are determined at build time */
   30 static const unsigned long personalities[] = {
   31 #include "personality.h"
   32 };
   33 
   34 /*
   35  *  stress_personality()
   36  *  stress system by rapid open/close calls
   37  */
   38 static int stress_personality(const args_t *args)
   39 {
   40     const ssize_t n = SIZEOF_ARRAY(personalities);
   41     bool failed[n];
   42 
   43     if (n == 0) {
   44         pr_inf("%s: no personalities to stress test\n", args->name);
   45         return EXIT_NOT_IMPLEMENTED;
   46     }
   47     (void)memset(failed, 0, sizeof(failed));
   48 
   49     if (args->instance == 0)
   50         pr_dbg("%s: exercising %zu personalities\n", args->name, n);
   51 
   52     do {
   53         ssize_t i, fails = 0;
   54 
   55         for (i = 0; i < n; i++) {
   56             unsigned long p = personalities[i];
   57             int ret;
   58 
   59             if (!g_keep_stressing_flag)
   60                 break;
   61             if (failed[i]) {
   62                 fails++;
   63                 continue;
   64             }
   65 
   66             ret = personality(p);
   67             if (ret < 0) {
   68                 failed[i] = true;
   69                 continue;
   70             }
   71             ret = personality(0xffffffffUL);
   72             if (ret < 0) {
   73                 pr_fail("%s: failed to get personality, errno=%d (%s)\n",
   74                     args->name, errno, strerror(errno));
   75             }
   76         }
   77         if (fails == n) {
   78             pr_fail("%s: all %zu personalities failed "
   79                 "to be set\n", args->name, fails);
   80             break;
   81         }
   82         inc_counter(args);
   83     } while (keep_stressing());
   84 
   85     return EXIT_SUCCESS;
   86 }
   87 
   88 stressor_info_t stress_personality_info = {
   89     .stressor = stress_personality,
   90     .class = CLASS_OS
   91 };
   92 #else
   93 stressor_info_t stress_personality_info = {
   94     .stressor = stress_not_implemented,
   95     .class = CLASS_OS
   96 };
   97 #endif