From: "Luka Marčetić" <paxcoder@gmail.com>
To: musl@lists.openwall.com
Cc: Solar Designer <solar@openwall.com>
Subject: Re: cluts weekly reports
Date: Wed, 03 Aug 2011 23:59:52 +0200 [thread overview]
Message-ID: <4E39C4D8.7040403@gmail.com> (raw)
In-Reply-To: <20110803181908.GZ132@brightrain.aerifal.cx>
[-- Attachment #1: Type: text/plain, Size: 283 bytes --]
On 08/03/2011 08:19 PM, Rich Felker wrote:
> Could you include some here?
> Rich
Attached are example files for the generator:
input.json - the input of the generator
output.c - (to be) the output of the generator
testgen.c - an additional header that output.c uses
Luka
[-- Attachment #2: input.json --]
[-- Type: application/json, Size: 402 bytes --]
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: output.c --]
[-- Type: text/x-csrc; name="output.c", Size: 3373 bytes --]
#include <errno.h>
#include <stdlib.h>
#include <signal.h>
#include <stdio.h>
#include <setjmp.h>
#include <string.h>
#include "common/common.h"
#include <stdlib.h>
/*
* Copyright (c) 2011 Luka Marčetić<paxcoder@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted.
*
* There's ABSOLUTELY NO WARRANTY, express or implied.
*/
jmp_buf env;
static void bridge_sig_jmp(int sig)
{
longjmp(env, sig);
}
int main()
{
union ret ret;
int sig, err;
unsigned int d, f, failed;
char *call, *more;
size_t i = 0;
struct arguments *arg;
struct sigaction oldact, act;
struct {
unsigned int
ret:1,
err:1,
sig:1;
} error, no_error;
memset(&no_error, 0, sizeof(no_error));
act.sa_handler = bridge_sig_jmp;
act.sa_flags = SA_NODEFER;
struct test t[] =
{
{
"realpath", 2,
1, (struct data[])
{
{//data
(struct arguments[])
{//arg
{2, (char *[]) {".", "./123456789"}},
{1, (char *[]) {NULL}},
},
(char *[]){NULL},
ENAMETOOLONG,
},
}
},
};
failed = 0;
for (f=0; f<sizeof(t)/sizeof(t[0]); ++f) {
memset(&error, 0, sizeof(error));
sigaction(SIGSEGV, &act, &oldact);
sig = 0;
for (d=0; !(sig = setjmp(env)) && !memcmp(&error, &no_error, sizeof(error)) && d<t[f].ndata; ++d) {
arg = t[f].data[d].arg; //shorthand args
for (i=0; !memcmp(&error, &no_error, sizeof(error)) && i<iters(t[f],d); ++i) {
switch (f) {
case 0:
if ((ret.s = realpath(ARGV(char *, 0), ARGV(char *, 1))) != *(char **)t[f].data[d].ret) {
call = sreturnf("%s(\"%s\", %d)", t[f].fn_name, ARGV(char *, 0), ARGV(int, 1));
error.ret=1;
more = sreturnf("%d instead of %d", ret.s, *(char *)t[f].data[d].ret);
}
if (t[f].data[d].err!=-1 && (err=errno) != t[f].data[d].err) {
call = sreturnf("%s(\"%s\", %d)", t[f].fn_name, ARGV(char *, 0), ARGV(int, 1));
error.err=1;
}
break;
}
}
}
error.sig = !(!sig);
sigaction(SIGSEGV, &oldact, NULL);
if (memcmp(&error, &no_error, sizeof(error))) {
if (error.sig)
fprintf(stderr, "Test %s caused a SIGSEGV (iteration %zu)\n",
t[f].fn_name, i
);
else {
--d;
--i;
}
if (error.ret) {
fprintf(stderr, "%s returned %s \n", call, more);
free(more);
}
if (error.err)
fprintf(stderr, "%s set errno to %s instead of %s \n",
call, e_name(err), e_name(t[f].data[d].err)
);
free(call);
++failed;
}
}
return failed;
}
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: testgen.c --]
[-- Type: text/x-csrc; name="testgen.c", Size: 2106 bytes --]
/*
* Copyright (c) 2011 Luka Marčetić<paxcoder@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted.
*
* There's ABSOLUTELY NO WARRANTY, express or implied.
*/
//A union for return values of functions
union ret {
char c;
char* s;
int i;
void* vp;
};
///Atrucutre designed to hold test data
struct test
{
char *fn_name; //function name for the output
unsigned int narg; //number of arguments that the function takes
unsigned int ndata; //number of test datasets
struct data {
struct arguments {unsigned int nr; void *vp;} *arg;
void *ret;
int err;
} *data;
};
///Handy macro to get a certain value from an element via the arg void pointer
///Note: it requires arg and i to be a pointer to struct arguments & an iterator
// hint: see iter and arg arguments for index()
#define ARGV(TYPE, INDEX) ((TYPE *) arg[INDEX].vp)[index(i, arg, INDEX)]
/**
** \returns the cardinality of a cartesian product of sets of arguments
** ie the number of iterations required to cover all argument values
** \param t a test to which the arguments belong
** \param d an index of the dataset from t to be taken into consideration
**/
size_t iters(struct test t, unsigned int d)
{
size_t i, product=1;
for (i=0; i<t.narg; ++i)
product *= t.data[d].arg[i].nr;
return product;
}
/**
** Given an iteration, returns the index of an argument value. That is,
** if iter is the number of a certain tuple from the cartesian product, and
** i the nr of an element from the tuple, the function returns its index in
** the original set - ie the (i-th) factor set to the cartesian product)
** \param iter current iteration
** \param arg a struct arguments pointer from struct test
** \param i index of the arguments for which the element index is requried
**/
size_t index(size_t iter, struct arguments *arg, int i)
{
size_t x = iter;
for(int j=0; j<i; ++j)
x /= arg[j].nr; //an integer value
x %= arg[i].nr;
return x;
}
next prev parent reply other threads:[~2011-08-03 21:59 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-18 17:10 Luka M.
2011-07-25 23:04 ` Luka M.
2011-08-03 0:56 ` Solar Designer
2011-08-03 1:21 ` Rich Felker
2011-08-03 13:15 ` Luka Marčetić
2011-08-03 13:31 ` Rich Felker
2011-08-03 14:51 ` Solar Designer
2011-08-03 17:08 ` Luka Marčetić
2011-08-03 17:22 ` Rich Felker
2011-08-03 18:03 ` Luka Marčetić
2011-08-03 18:19 ` Rich Felker
2011-08-03 18:38 ` Luka Marčetić
2011-08-03 21:59 ` Luka Marčetić [this message]
2011-08-03 22:45 ` Solar Designer
2011-08-03 22:53 ` Rich Felker
2011-08-04 11:43 ` Luka Marčetić
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=4E39C4D8.7040403@gmail.com \
--to=paxcoder@gmail.com \
--cc=musl@lists.openwall.com \
--cc=solar@openwall.com \
/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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).