Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: allow user to select tests via command line args #1211

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ noinst_HEADERS += src/precomputed_ecmult_gen.h
noinst_HEADERS += src/assumptions.h
noinst_HEADERS += src/checkmem.h
noinst_HEADERS += src/util.h
noinst_HEADERS += src/cli_util.h
noinst_HEADERS += src/int128.h
noinst_HEADERS += src/int128_impl.h
noinst_HEADERS += src/int128_native.h
Expand Down
1 change: 1 addition & 0 deletions src/bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "../include/secp256k1.h"
#include "util.h"
#include "cli_util.h"
#include "bench.h"

static void help(int default_iters) {
Expand Down
41 changes: 1 addition & 40 deletions src/bench.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>

#if (defined(_MSC_VER) && _MSC_VER >= 1900)
# include <time.h>
Expand Down Expand Up @@ -79,7 +78,7 @@ static void print_number(const int64_t x) {
y /= 10;
}
} else if (c == 0) { /* fractional part is 0 */
buffer[--ptr] = '0';
buffer[--ptr] = '0';
}
buffer[--ptr] = '.';
do {
Expand Down Expand Up @@ -129,44 +128,6 @@ static void run_benchmark(char *name, void (*benchmark)(void*, int), void (*setu
printf("\n");
}

static int have_flag(int argc, char** argv, char *flag) {
char** argm = argv + argc;
argv++;
while (argv != argm) {
if (strcmp(*argv, flag) == 0) {
return 1;
}
argv++;
}
return 0;
}

/* takes an array containing the arguments that the user is allowed to enter on the command-line
returns:
- 1 if the user entered an invalid argument
- 0 if all the user entered arguments are valid */
static int have_invalid_args(int argc, char** argv, char** valid_args, size_t n) {
size_t i;
int found_valid;
char** argm = argv + argc;
argv++;

while (argv != argm) {
found_valid = 0;
for (i = 0; i < n; i++) {
if (strcmp(*argv, valid_args[i]) == 0) {
found_valid = 1; /* user entered a valid arg from the list */
break;
}
}
if (found_valid == 0) {
return 1; /* invalid arg found */
}
argv++;
}
return 0;
}

static int get_iters(int default_iters) {
char* env = getenv("SECP256K1_BENCH_ITERS");
if (env) {
Expand Down
1 change: 1 addition & 0 deletions src/bench_ecmult.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "../include/secp256k1.h"

#include "util.h"
#include "cli_util.h"
#include "hash_impl.h"
#include "field_impl.h"
#include "group_impl.h"
Expand Down
1 change: 1 addition & 0 deletions src/bench_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "assumptions.h"
#include "util.h"
#include "cli_util.h"
#include "hash_impl.h"
#include "field_impl.h"
#include "group_impl.h"
Expand Down
50 changes: 50 additions & 0 deletions src/cli_util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/***********************************************************************
* Copyright (c) 2023 Jonas Nick *
* Distributed under the MIT software license, see the accompanying *
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
***********************************************************************/

#ifndef SECP256K1_CLI_UTIL_H
#define SECP256K1_CLI_UTIL_H

#include <string.h>

static int have_flag(int argc, char** argv, char *flag) {
char** argm = argv + argc;
argv++;
while (argv != argm) {
if (strcmp(*argv, flag) == 0) {
return 1;
}
argv++;
}
return 0;
}

/* takes an array containing the arguments that the user is allowed to enter on the command-line
returns:
- 1 if the user entered an invalid argument
- 0 if all the user entered arguments are valid */
static int have_invalid_args(int argc, char** argv, char** valid_args, size_t n) {
size_t i;
int found_valid;
char** argm = argv + argc;
argv++;

while (argv != argm) {
found_valid = 0;
for (i = 0; i < n; i++) {
if (strcmp(*argv, valid_args[i]) == 0) {
found_valid = 1; /* user entered a valid arg from the list */
break;
}
}
if (found_valid == 0) {
return 1; /* invalid arg found */
}
argv++;
}
return 0;
}

#endif /* SECP256K1_CLI_UTIL_H */