172d849c7SHans Petter Selasky /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
372d849c7SHans Petter Selasky *
472d849c7SHans Petter Selasky * Copyright (c) 2020 Mellanox Technologies. All rights reserved.
572d849c7SHans Petter Selasky *
672d849c7SHans Petter Selasky * Redistribution and use in source and binary forms, with or without
772d849c7SHans Petter Selasky * modification, are permitted provided that the following conditions
872d849c7SHans Petter Selasky * are met:
972d849c7SHans Petter Selasky * 1. Redistributions of source code must retain the above copyright
1072d849c7SHans Petter Selasky * notice, this list of conditions and the following disclaimer.
1172d849c7SHans Petter Selasky * 2. Redistributions in binary form must reproduce the above copyright
1272d849c7SHans Petter Selasky * notice, this list of conditions and the following disclaimer in the
1372d849c7SHans Petter Selasky * documentation and/or other materials provided with the distribution.
1472d849c7SHans Petter Selasky *
1572d849c7SHans Petter Selasky * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1672d849c7SHans Petter Selasky * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1772d849c7SHans Petter Selasky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1872d849c7SHans Petter Selasky * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1972d849c7SHans Petter Selasky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2072d849c7SHans Petter Selasky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2172d849c7SHans Petter Selasky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2272d849c7SHans Petter Selasky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2372d849c7SHans Petter Selasky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2472d849c7SHans Petter Selasky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2572d849c7SHans Petter Selasky * SUCH DAMAGE.
2672d849c7SHans Petter Selasky */
2772d849c7SHans Petter Selasky
2872d849c7SHans Petter Selasky #include <stdio.h>
2972d849c7SHans Petter Selasky #include <stdlib.h>
3072d849c7SHans Petter Selasky #include <stdint.h>
3172d849c7SHans Petter Selasky #include <unistd.h>
3272d849c7SHans Petter Selasky #include <string.h>
3372d849c7SHans Petter Selasky #include <err.h>
3472d849c7SHans Petter Selasky
3572d849c7SHans Petter Selasky #include <sys/sysctl.h>
3672d849c7SHans Petter Selasky
3772d849c7SHans Petter Selasky #include "../kern_testfrwk.h"
3872d849c7SHans Petter Selasky #include "../callout_test.h"
3972d849c7SHans Petter Selasky
4072d849c7SHans Petter Selasky static struct kern_test kern_test = {
4172d849c7SHans Petter Selasky .num_threads = 1,
4272d849c7SHans Petter Selasky .tot_threads_running = 1,
4372d849c7SHans Petter Selasky };
4472d849c7SHans Petter Selasky
4572d849c7SHans Petter Selasky static struct callout_test callout_test = {
4672d849c7SHans Petter Selasky .number_of_callouts = 1,
4772d849c7SHans Petter Selasky .test_number = 0,
4872d849c7SHans Petter Selasky };
4972d849c7SHans Petter Selasky
5072d849c7SHans Petter Selasky static void
usage()5172d849c7SHans Petter Selasky usage()
5272d849c7SHans Petter Selasky {
5372d849c7SHans Petter Selasky fprintf(stderr, "Usage: runtest -n <testname> -j <numthreads> [ -c <numcallouts> -t <testnumber> ]\n");
5472d849c7SHans Petter Selasky exit(0);
5572d849c7SHans Petter Selasky }
5672d849c7SHans Petter Selasky
5772d849c7SHans Petter Selasky int
main(int argc,char ** argv)5872d849c7SHans Petter Selasky main(int argc, char **argv)
5972d849c7SHans Petter Selasky {
6072d849c7SHans Petter Selasky static const char options[] = "n:j:c:t:h";
6172d849c7SHans Petter Selasky int ch;
6272d849c7SHans Petter Selasky
6372d849c7SHans Petter Selasky while ((ch = getopt(argc, argv, options)) != -1) {
6472d849c7SHans Petter Selasky switch (ch) {
6572d849c7SHans Petter Selasky case 'n':
6672d849c7SHans Petter Selasky strlcpy(kern_test.name, optarg, sizeof(kern_test.name));
6772d849c7SHans Petter Selasky break;
6872d849c7SHans Petter Selasky case 'j':
6972d849c7SHans Petter Selasky kern_test.num_threads =
7072d849c7SHans Petter Selasky kern_test.tot_threads_running = atoi(optarg);
7172d849c7SHans Petter Selasky break;
7272d849c7SHans Petter Selasky case 'c':
7372d849c7SHans Petter Selasky callout_test.number_of_callouts = atoi(optarg);
7472d849c7SHans Petter Selasky break;
7572d849c7SHans Petter Selasky case 't':
7672d849c7SHans Petter Selasky callout_test.test_number = atoi(optarg);
7772d849c7SHans Petter Selasky break;
7872d849c7SHans Petter Selasky default:
7972d849c7SHans Petter Selasky usage();
8072d849c7SHans Petter Selasky break;
8172d849c7SHans Petter Selasky }
8272d849c7SHans Petter Selasky }
8372d849c7SHans Petter Selasky
8472d849c7SHans Petter Selasky if (kern_test.name[0] == 0)
8572d849c7SHans Petter Selasky usage();
8672d849c7SHans Petter Selasky if (strcmp(kern_test.name, "callout_test") == 0)
8772d849c7SHans Petter Selasky memcpy(kern_test.test_options, &callout_test, sizeof(callout_test));
8872d849c7SHans Petter Selasky
8972d849c7SHans Petter Selasky if (sysctlbyname("kern.testfrwk.runtest", NULL, NULL, &kern_test, sizeof(kern_test)) != 0)
9072d849c7SHans Petter Selasky errx(1, "Test '%s' could not be started", kern_test.name);
9172d849c7SHans Petter Selasky return (0);
9272d849c7SHans Petter Selasky }
93