From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] thp01: Find largest arguments size
Date: Fri, 1 Sep 2017 12:03:19 +0200 [thread overview]
Message-ID: <20170901100319.GA26071@rei> (raw)
In-Reply-To: <20170831083407.28402-1-rpalethorpe@suse.com>
Hi!
> +#include <errno.h>
> #include <sys/types.h>
> #include <sys/resource.h>
> #include <sys/wait.h>
> @@ -38,56 +39,72 @@
> #include <stdlib.h>
> #include <unistd.h>
> #include "mem.h"
> +#include "tst_minmax.h"
> +#include "tst_safe_sysv_ipc.h"
>
> -#define ARRAY_SZ 256
> +#define ARGS_SZ 256
>
> -static int ps;
> -static long length;
> -static char *array[ARRAY_SZ];
> +static int shm_id;
> +static char *args[ARGS_SZ];
> static char *arg;
> -static struct rlimit rl = {
> - .rlim_cur = RLIM_INFINITY,
> - .rlim_max = RLIM_INFINITY,
> -};
> +static long *arg_count;
>
> static void thp_test(void)
> {
> - int i;
> - pid_t pid;
> -
> - switch (pid = SAFE_FORK()) {
> - case 0:
> - memset(arg, 'c', length - 1);
> - arg[length - 1] = '\0';
> - array[0] = "true";
> - for (i = 1; i < ARRAY_SZ - 1; i++)
> - array[i] = arg;
> - array[ARRAY_SZ - 1] = NULL;
> - if (setrlimit(RLIMIT_STACK, &rl) == -1) {
> - perror("setrlimit");
> - exit(1);
> - }
> - if (execvp("true", array) == -1) {
> - perror("execvp");
> - exit(1);
> - }
> - default:
> - tst_reap_children();
> + pid_t pid = SAFE_FORK();
> +
> + if (!arg_count)
> + tst_brk(TBROK, "No shared memory");
> +
> + if (!pid) {
> + args[*arg_count] = NULL;
> +
> + do {
> + TEST(execvp("true", args));
> + args[--(*arg_count)] = NULL;
> + } while (*arg_count > 0 && TEST_ERRNO == E2BIG);
Hmm, for how long does this loop runs? If it's more than
half of a second or so we should consider using binary
search to reach the maximal size of arguments...
> + tst_brk(TBROK | TTERRNO, "execvp(\"true\", ...)");
> }
>
> + tst_reap_children();
> tst_res(TPASS, "system didn't crash, pass.");
> }
>
> static void setup(void)
> {
> - ps = sysconf(_SC_PAGESIZE);
> - length = 32 * ps;
> - arg = SAFE_MALLOC(length);
> + struct rlimit rl = {
> + .rlim_cur = RLIM_INFINITY,
> + .rlim_max = RLIM_INFINITY,
> + };
> + int i;
> + long arg_len;
> +
> + shm_id = SAFE_SHMGET(IPC_PRIVATE, sizeof(long),
> + IPC_CREAT | IPC_EXCL);
> + arg_count = SAFE_SHMAT(shm_id, NULL, 0);
Can we, pretty please, use mmap() to map a page of shared memory instead
of using the System V shared memory that has ugly API and system
persistence?
> + arg_len = 32 * sysconf(_SC_PAGESIZE);
> + arg = SAFE_MALLOC(arg_len);
> + memset(arg, 'c', arg_len - 1);
> + arg[arg_len - 1] = '\0';
> +
> + args[0] = "true";
> + *arg_count = ARGS_SZ - 1;
> + for (i = 1; i < *arg_count; i++)
> + args[i] = arg;
> +
> + SAFE_SETRLIMIT(RLIMIT_STACK, &rl);
> }
>
> static void cleanup(void)
> {
> - free(arg);
> + if (arg)
> + free(arg);
> + if (arg_count)
> + SAFE_SHMDT(arg_count);
> + if (shm_id)
> + SAFE_SHMCTL(shm_id, IPC_RMID, NULL);
> }
>
> static struct tst_test test = {
> --
> 2.14.1
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
next prev parent reply other threads:[~2017-09-01 10:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-31 8:34 [LTP] [PATCH] thp01: Find largest arguments size Richard Palethorpe
2017-09-01 7:05 ` Li Wang
2017-09-01 9:34 ` Richard Palethorpe
2017-09-01 10:44 ` Li Wang
2017-09-01 10:03 ` Cyril Hrubis [this message]
2017-09-01 14:13 ` [LTP] [PATCH v2] " Richard Palethorpe
2017-09-04 11:29 ` Li Wang
2017-09-11 9:26 ` Richard Palethorpe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170901100319.GA26071@rei \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox