Exemplo n.º 1
0
/* performs properties change with support of undoing */
static void
file_attrib(char *path, DWORD add, DWORD sub, int recurse_dirs)
{
	/* FIXME: set attributes recursively. */

	DWORD attrs = GetFileAttributes(path);
	if(attrs == INVALID_FILE_ATTRIBUTES)
	{
		LOG_WERROR(GetLastError());
		return;
	}
	if(add != 0)
	{
		const size_t wadd = add;
		if(perform_operation(OP_ADDATTR, NULL, (void *)wadd, path, NULL) == 0)
		{
			add_operation(OP_ADDATTR, (void *)wadd, (void *)(~attrs & wadd), path,
					"");
		}
	}
	if(sub != 0)
	{
		const size_t wsub = sub;
		if(perform_operation(OP_SUBATTR, NULL, (void *)wsub, path, NULL) == 0)
		{
			add_operation(OP_SUBATTR, (void *)wsub, (void *)(~attrs & wsub), path,
					"");
		}
	}
}
Exemplo n.º 2
0
static int instream_start_pa(SoundIoPrivate *si, SoundIoInStreamPrivate *is) {
    SoundIoInStream *instream = &is->pub;
    SoundIoInStreamPulseAudio *ispa = &is->backend_data.pulseaudio;
    SoundIoPulseAudio *sipa = &si->backend_data.pulseaudio;
    pa_threaded_mainloop_lock(sipa->main_loop);

    pa_stream_flags_t flags = PA_STREAM_AUTO_TIMING_UPDATE;
    if (instream->software_latency > 0.0)
        flags = (pa_stream_flags_t) (flags|PA_STREAM_ADJUST_LATENCY);

    int err = pa_stream_connect_record(ispa->stream,
            instream->device->id,
            &ispa->buffer_attr, flags);
    if (err) {
        pa_threaded_mainloop_unlock(sipa->main_loop);
        return SoundIoErrorOpeningDevice;
    }

    while (!ispa->stream_ready)
        pa_threaded_mainloop_wait(sipa->main_loop);

    pa_operation *update_timing_info_op = pa_stream_update_timing_info(ispa->stream, timing_update_callback, si);
    if ((err = perform_operation(si, update_timing_info_op))) {
        pa_threaded_mainloop_unlock(sipa->main_loop);
        return err;
    }


    pa_threaded_mainloop_unlock(sipa->main_loop);
    return 0;
}
Exemplo n.º 3
0
// Ensure perform_operation() succeeds given valid input parameters.
void test_perform_operation(void **state) {
	const OperatorFunction operator_functions[] = {
		{"+", binary_operator},
		{"*", binary_operator},
	};
	char *args[] = {
		"1", "+", "3", "*", "10",
	};
	int number_of_intermediate_values;
	int *intermediate_values;
	int error_occurred;

	// Setup return values of mock operator functions.
	// Addition.
	expect_value(binary_operator, a, 1);
	expect_value(binary_operator, b, 3);
	will_return(binary_operator, 4);

	// Multiplication.
	expect_value(binary_operator, a, 4);
	expect_value(binary_operator, b, 10);
	will_return(binary_operator, 40);

	assert_int_equal(perform_operation(
	    array_length(args), args, array_length(operator_functions),
	    operator_functions, &number_of_intermediate_values,
	    &intermediate_values, &error_occurred), 40);
	assert_int_equal(error_occurred, 0);

	assert_true(intermediate_values);
	assert_int_equal(intermediate_values[0], 4);
	assert_int_equal(intermediate_values[1], 40);
	test_free(intermediate_values);
}
Exemplo n.º 4
0
char* solve(char *input, float *answer) {
  int read_count;
  float new_number;
  char operator = '+';

  while (operator != ')' && operator != '=') {
    new_number = 0;

    if (input[0] == '(') {
      printf("found new sub-expression!\n");
      input = solve(input+1, &new_number);
    } else {
      printf("input starts with %c\n", input[0]);
      sscanf(input, "%f%n", &new_number, &read_count);
      input += read_count;
    }
    printf("%.1f %c %.1f\n", *answer, operator, new_number);

    perform_operation(answer, operator, new_number);

    operator = input[0];
    input++;
  }

  printf("exiting sub-expression or end\n");
  return input;
}
Exemplo n.º 5
0
int
example_syscall(struct credential *cred, int index, int op)
{
	/*
	 * CHECK: new    [[INST0:[0-9]+]]: [[INIT:1:0x0]]
	 */

	struct object *o;
	int error = get_object(index, &o);
	if (error != 0)
		return (error);

	/*
	 * perform_operation() contains the NOW event:
	 * CHECK: clone  [[INST0]]:[[INIT]] -> [[INST1:[0-9]+]]:[[NOW:[0-9]+:0x1]]
	 */
	perform_operation(op, o);

	// Error: missing release(o)!
	//release(o);

	/*
	 * ERR: Instance {{[0-9]+}} is in state {{[0-9]+}}
	 * ERR: but received event '{{.*}}example_syscall{{.*}}cleanup
	 * ERR: causes transition in: [
	 * ERR:     ({{[0-9]+}}:0x0 -> {{[0-9]+}}:0x0 <clean>)
	 * ERR:     ({{[0-9]+}}:0x1 -> {{[0-9]+}}:0x{{[01]}} <clean>)
	 * ERR: ]
	 */
	return 0;
}
Exemplo n.º 6
0
int main(int argc, char *argv[]) {
    int return_value;
    int number_of_intermediate_values;
    int *intermediate_values;
    // Peform the operation.
    const int result = perform_operation(
        argc - 1, &argv[1],
        sizeof(operator_function_map) / sizeof(operator_function_map[0]),
        operator_function_map, &number_of_intermediate_values,
        &intermediate_values, &return_value);

    // If no errors occurred display the result.
    if (!return_value && argc > 1) {
        unsigned int i;
        unsigned int intermediate_value_index = 0;
        printf("%s\n", argv[1]);
        for (i = 2; i < argc; i += 2) {
            assert(intermediate_value_index < number_of_intermediate_values);
            printf("  %s %s = %d\n", argv[i], argv[i + 1],
                   intermediate_values[intermediate_value_index++]);
        }
        printf("= %d\n", result);
    }
    if (intermediate_values) {
        free(intermediate_values);
    }

    return return_value;
}
Exemplo n.º 7
0
int
example_syscall(struct credential *cred, int index, int op)
{
	struct object *o;
	int error = get_object(index, &o);
	if (error != 0)
		return (error);

	des_cblock		des_key;
	des_key_schedule	key_schedule;

	crypto_setup(&des_key, &key_schedule);

	if ((error = security_check(cred, o, op))) return error;
	some_helper(op);
	void_helper(o);
	perform_operation(op, o);

	crypto_encrypt(&des_key, &key_schedule);

	log_audit_record(o, op);

	release(o);

	return 0;
}
Exemplo n.º 8
0
static int instream_start_pa(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) {
    struct SoundIoInStream *instream = &is->pub;
    struct SoundIoInStreamPulseAudio *ispa = &is->backend_data.pulseaudio;
    struct SoundIoPulseAudio *sipa = &si->backend_data.pulseaudio;
    pa_threaded_mainloop_lock(sipa->main_loop);

    pa_stream_flags_t flags = (pa_stream_flags_t)(PA_STREAM_AUTO_TIMING_UPDATE | PA_STREAM_INTERPOLATE_TIMING);

    int err = pa_stream_connect_record(ispa->stream,
            instream->device->id,
            &ispa->buffer_attr, flags);
    if (err) {
        pa_threaded_mainloop_unlock(sipa->main_loop);
        return SoundIoErrorOpeningDevice;
    }

    while (!SOUNDIO_ATOMIC_LOAD(ispa->stream_ready))
        pa_threaded_mainloop_wait(sipa->main_loop);

    pa_operation *update_timing_info_op = pa_stream_update_timing_info(ispa->stream, timing_update_callback, si);
    if ((err = perform_operation(si, update_timing_info_op))) {
        pa_threaded_mainloop_unlock(sipa->main_loop);
        return err;
    }


    pa_threaded_mainloop_unlock(sipa->main_loop);
    return 0;
}
Exemplo n.º 9
0
static void
file_chmod(char *path, const char *mode, const char *inv_mode, int recurse_dirs)
{
	int op = recurse_dirs ? OP_CHMODR : OP_CHMOD;

	if(perform_operation(op, (void *)mode, path, NULL) == 0)
		add_operation(op, strdup(mode), strdup(inv_mode), path, "");
}
Exemplo n.º 10
0
// Ensure perform_operation() returns 0 when no arguments are specified.
void test_perform_operation_no_arguments(void **state) {
	int number_of_intermediate_values;
	int *intermediate_values;
	int error_occurred;
	assert_int_equal(perform_operation(
	    0, NULL, 0, NULL, &number_of_intermediate_values, &intermediate_values,
	    &error_occurred), 0);
	assert_int_equal(error_occurred, 0);
}
Exemplo n.º 11
0
void main(void)
{  long tests;
   fscanf(in,"%ld\n",&tests);
   for(long test=0;test<tests;test++){
	n=0, val=0, read=0, op='+';
	fscanf(in,"%ld",&n);
	while((ch=fgetc(in))!=13)
	{ if(ch==EOF) break;
	  if(ch=='+' || ch=='^') perform_operation();
	  if(ch>='0' && ch<='9')
	    if(op=='+') read=(read*10+ch-'0')%n;
	      else read=(read*10+ch-'0')%(n-1);
	}
	perform_operation();
	fprintf(out,"%ld\n",val);
   };
   fclose(in);
   fclose(out);
}
Exemplo n.º 12
0
int
example_syscall(struct credential *cred)
{
    struct object *o;

    int error = get_object(&o);
    if (error != 0)
        return (error);

    return perform_operation(o);
}
Exemplo n.º 13
0
/* Ensure perform_operation() asserts when a NULL operator_functions array is
 * specified. */
void test_perform_operation_null_operator_functions(void **state) {
	char *args[] = {
		"1", "+", "2", "*", "4"
	};
	int number_of_intermediate_values;
	int *intermediate_values;
	int error_occurred;
	expect_assert_failure(perform_operation(
	    array_length(args), args, 1, NULL, &number_of_intermediate_values,
	    &intermediate_values, &error_occurred));
}
Exemplo n.º 14
0
// Ensure perform_operation() asserts when a NULL arguments array is specified.
void test_perform_operation_null_args(void **state) {
	const OperatorFunction operator_functions[] = {
		{"+", binary_operator},
	};
	int number_of_intermediate_values;
	int *intermediate_values;
	int error_occurred;
	expect_assert_failure(perform_operation(
	    1, NULL, array_length(operator_functions), operator_functions,
	    &number_of_intermediate_values, &intermediate_values,
	    &error_occurred));
}
Exemplo n.º 15
0
/* Ensure perform_operation() asserts when a NULL pointer is specified for
 * intermediate_values. */
void test_perform_operation_null_intermediate_values(void **state) {
	const OperatorFunction operator_functions[] = {
		{"+", binary_operator},
	};
	char *args[] = {
		"1", "+", "2", "*", "4"
	};
	int number_of_intermediate_values;
	int error_occurred;
	expect_assert_failure(perform_operation(
	    array_length(args), args, array_length(operator_functions),
	    operator_functions, &number_of_intermediate_values, NULL,
	    &error_occurred));
}
Exemplo n.º 16
0
/* Ensure perform_operation() asserts when a NULL pointer is specified for
 * number_of_intermediate_values. */
static void test_perform_operation_null_number_of_intermediate_values(void **state) {
	const OperatorFunction operator_functions[] = {
		{"+", binary_operator},
	};
	const char *args[] = {
		"1", "+", "2", "*", "4"
	};
	int *intermediate_values;
	int error_occurred;

        (void) state; /* unused */

	expect_assert_failure(perform_operation(
	    array_length(args), (char **) args, 1, operator_functions, NULL,
	    &intermediate_values, &error_occurred));
}
Exemplo n.º 17
0
int do_stuff(const Params * parameters)
{
	if (parameters->Flags & FLAG_HELP || ((parameters->Flags | FLAG_LOAD |  FLAG_SAVE) != parameters->Flags) )
	{/* We wanted HELP or we did not get SAVE or LOAD */
		print_help(); /* tell the loser what to do, then :-) */
		return 0;
	}
	int verbose = parameters->Flags & FLAG_VERBOSE;

	int image_handle;
	int w, h;
	ILboolean result;

	/* Quite obvious stuff, just load an image */
	ilGenImages(1, & image_handle);
	ilBindImage(image_handle);
	result = ilLoadImage(parameters->Load_filename);
	if (result == IL_FALSE)
	{
		int error = ilGetError();
		fprintf(stderr, "Error: Something went wrong when loading file '%s' (%s)\n", parameters->Load_filename, iluErrorString(error));
		return error;
	}
	/* If we get image's dimensions, people will believe that we have actually loaded something :-) */
	w = ilGetInteger(IL_IMAGE_WIDTH);
	h = ilGetInteger(IL_IMAGE_HEIGHT);
	if (verbose)
		printf("Loaded '%s', size %dx%d\n", parameters->Load_filename, w, h);
	/* Now let's do our stuff!!! */
	int i;
	for (i = 0; i < parameters->Calls_count; i++)
		perform_operation(parameters->Calls_strings[i], verbose);
	/* our stuff has been done... */

	result = ilSaveImage(parameters->Save_filename);
	if (result == IL_FALSE)
	{
		int error = ilGetError();
		fprintf(stderr, "Error: Something went wrong when saving file '%s' (%s)\n", parameters->Save_filename, iluErrorString(error));
		ilDeleteImages(1, & image_handle);
		return error;
	}
	ilDeleteImages(1, & image_handle);
	return 0;
}
Exemplo n.º 18
0
/* Ensure perform_operation() returns an error when an integer doesn't follow
 * an operator. */
void test_perform_operation_no_integer_after_operator(void **state) {
	const OperatorFunction operator_functions[] = {
		{"+", binary_operator},
	};
	char *args[] = {
		"1", "+", "test",
	};
	int number_of_intermediate_values;
	int *intermediate_values;
	int error_occurred;

	expect_string(example_test_fprintf, temporary_buffer,
	              "Unable to parse integer test of argument 2\n");

	assert_int_equal(perform_operation(
	    array_length(args), args, array_length(operator_functions),
	    operator_functions, &number_of_intermediate_values,
	    &intermediate_values, &error_occurred), 0);
	assert_int_equal(error_occurred, 1);
}
Exemplo n.º 19
0
/* Ensure perform_operation() returns an error when nothing follows an
 * operator. */
static void test_perform_operation_missing_argument(void **state) {
	const OperatorFunction operator_functions[] = {
		{"+", binary_operator},
	};
	const char *args[] = {
		"1", "+",
	};
	int number_of_intermediate_values;
	int *intermediate_values;
	int error_occurred;

        (void) state; /* unused */

	expect_string(example_test_fprintf, temporary_buffer,
	              "Binary operator + missing argument\n");

	assert_int_equal(perform_operation(
	    array_length(args), (char **) args, array_length(operator_functions),
	    operator_functions, &number_of_intermediate_values,
	    &intermediate_values, &error_occurred), 0);
	assert_int_equal(error_occurred, 1);
}
Exemplo n.º 20
0
/* Ensure perform_operation() returns an error if the first argument isn't
 * an integer string. */
static void test_perform_operation_first_arg_not_integer(void **state) {
	const OperatorFunction operator_functions[] = {
		{"+", binary_operator},
	};
	const char *args[] = {
		"test", "+", "2", "*", "4"
	};
	int number_of_intermediate_values;
	int *intermediate_values;
	int error_occurred;

        (void) state; /* unused */

	expect_string(example_test_fprintf, temporary_buffer,
	              "Unable to parse integer from argument test\n");

	assert_int_equal(perform_operation(
	    array_length(args), (char **) args, array_length(operator_functions),
	    operator_functions, &number_of_intermediate_values,
	    &intermediate_values, &error_occurred), 0);
	assert_int_equal(error_occurred, 1);
}
Exemplo n.º 21
0
void
caller_with_literals()
{
	perform_operation(3, 0);
}
Exemplo n.º 22
0
// call this while holding the main loop lock
static int refresh_devices(struct SoundIoPrivate *si) {
    struct SoundIo *soundio = &si->pub;
    struct SoundIoPulseAudio *sipa = &si->backend_data.pulseaudio;

    assert(!sipa->current_devices_info);
    sipa->current_devices_info = ALLOCATE(struct SoundIoDevicesInfo, 1);
    if (!sipa->current_devices_info)
        return SoundIoErrorNoMem;

    pa_operation *list_sink_op = pa_context_get_sink_info_list(sipa->pulse_context, sink_info_callback, si);
    pa_operation *list_source_op = pa_context_get_source_info_list(sipa->pulse_context, source_info_callback, si);
    pa_operation *server_info_op = pa_context_get_server_info(sipa->pulse_context, server_info_callback, si);

    int err;
    if ((err = perform_operation(si, list_sink_op))) {
        return err;
    }
    if ((err = perform_operation(si, list_source_op))) {
        return err;
    }
    if ((err = perform_operation(si, server_info_op))) {
        return err;
    }

    if (sipa->device_query_err) {
        return sipa->device_query_err;
    }

    // based on the default sink name, figure out the default output index
    // if the name doesn't match just pick the first one. if there are no
    // devices then we need to set it to -1.
    sipa->current_devices_info->default_output_index = -1;
    sipa->current_devices_info->default_input_index = -1;

    if (sipa->current_devices_info->input_devices.length > 0) {
        sipa->current_devices_info->default_input_index = 0;
        for (int i = 0; i < sipa->current_devices_info->input_devices.length; i += 1) {
            struct SoundIoDevice *device = SoundIoListDevicePtr_val_at(
                    &sipa->current_devices_info->input_devices, i);

            assert(device->aim == SoundIoDeviceAimInput);
            if (strcmp(device->id, sipa->default_source_name) == 0) {
                sipa->current_devices_info->default_input_index = i;
            }
        }
    }

    if (sipa->current_devices_info->output_devices.length > 0) {
        sipa->current_devices_info->default_output_index = 0;
        for (int i = 0; i < sipa->current_devices_info->output_devices.length; i += 1) {
            struct SoundIoDevice *device = SoundIoListDevicePtr_val_at(
                    &sipa->current_devices_info->output_devices, i);

            assert(device->aim == SoundIoDeviceAimOutput);
            if (strcmp(device->id, sipa->default_sink_name) == 0) {
                sipa->current_devices_info->default_output_index = i;
            }
        }
    }

    soundio_destroy_devices_info(sipa->ready_devices_info);
    sipa->ready_devices_info = sipa->current_devices_info;
    sipa->current_devices_info = NULL;
    pa_threaded_mainloop_signal(sipa->main_loop, 0);
    soundio->on_events_signal(soundio);

    return 0;
}
Exemplo n.º 23
0
static int outstream_open_pa(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) {
    struct SoundIoOutStreamPulseAudio *ospa = &os->backend_data.pulseaudio;
    struct SoundIoOutStream *outstream = &os->pub;

    if ((unsigned)outstream->layout.channel_count > PA_CHANNELS_MAX)
        return SoundIoErrorIncompatibleBackend;

    if (!outstream->name)
        outstream->name = "SoundIoOutStream";

    struct SoundIoPulseAudio *sipa = &si->backend_data.pulseaudio;
    SOUNDIO_ATOMIC_STORE(ospa->stream_ready, false);
    SOUNDIO_ATOMIC_FLAG_TEST_AND_SET(ospa->clear_buffer_flag);

    assert(sipa->pulse_context);

    pa_threaded_mainloop_lock(sipa->main_loop);

    pa_sample_spec sample_spec;
    sample_spec.format = to_pulseaudio_format(outstream->format);
    sample_spec.rate = outstream->sample_rate;

    sample_spec.channels = outstream->layout.channel_count;
    pa_channel_map channel_map = to_pulseaudio_channel_map(&outstream->layout);

    ospa->stream = pa_stream_new(sipa->pulse_context, outstream->name, &sample_spec, &channel_map);
    if (!ospa->stream) {
        pa_threaded_mainloop_unlock(sipa->main_loop);
        outstream_destroy_pa(si, os);
        return SoundIoErrorNoMem;
    }
    pa_stream_set_state_callback(ospa->stream, playback_stream_state_callback, os);

    ospa->buffer_attr.maxlength = UINT32_MAX;
    ospa->buffer_attr.tlength = UINT32_MAX;
    ospa->buffer_attr.prebuf = 0;
    ospa->buffer_attr.minreq = UINT32_MAX;
    ospa->buffer_attr.fragsize = UINT32_MAX;

    int bytes_per_second = outstream->bytes_per_frame * outstream->sample_rate;
    if (outstream->software_latency > 0.0) {
        int buffer_length = outstream->bytes_per_frame *
            ceil_dbl_to_int(outstream->software_latency * bytes_per_second / (double)outstream->bytes_per_frame);

        ospa->buffer_attr.maxlength = buffer_length;
        ospa->buffer_attr.tlength = buffer_length;
    }

    pa_stream_flags_t flags = (pa_stream_flags_t)(PA_STREAM_START_CORKED | PA_STREAM_AUTO_TIMING_UPDATE |
            PA_STREAM_INTERPOLATE_TIMING);

    int err = pa_stream_connect_playback(ospa->stream,
            outstream->device->id, &ospa->buffer_attr,
            flags, NULL, NULL);
    if (err) {
        pa_threaded_mainloop_unlock(sipa->main_loop);
        return SoundIoErrorOpeningDevice;
    }

    while (!SOUNDIO_ATOMIC_LOAD(ospa->stream_ready))
        pa_threaded_mainloop_wait(sipa->main_loop);

    pa_operation *update_timing_info_op = pa_stream_update_timing_info(ospa->stream, timing_update_callback, si);
    if ((err = perform_operation(si, update_timing_info_op))) {
        pa_threaded_mainloop_unlock(sipa->main_loop);
        return err;
    }

    size_t writable_size = pa_stream_writable_size(ospa->stream);
    outstream->software_latency = ((double)writable_size) / (double)bytes_per_second;

    pa_threaded_mainloop_unlock(sipa->main_loop);

    return 0;
}
Exemplo n.º 24
0
static void
perform_merge(int op)
{
#ifndef _WIN32
	struct stat src, dst;
#endif

	ops_t *ops;

	create_empty_dir("first");
	create_empty_dir("first/nested1");
	create_empty_dir("first/nested1/nested2");
	create_empty_file("first/nested1/nested2/file");

	create_empty_dir("second");
	create_empty_dir("second/nested1");

#ifndef _WIN32
	/* Something about GNU Hurd and OS X differs, so skip this workaround there.
	 * Really need to figure out what's wrong with this thing... */
#if !defined(__gnu_hurd__) && !defined(__APPLE__)
	{
		struct timeval tv[2];
		gettimeofday(&tv[0], NULL);
		tv[1] = tv[0];

		/* This might be Linux-specific, but for the test to work properly access
		 * time should be newer than modification time, in which case it's not
		 * changed on listing directory. */
		tv[0].tv_sec += 3;
		tv[0].tv_usec += 4;
		tv[1].tv_sec += 1;
		tv[1].tv_usec += 2;
		utimes("first/nested1", tv);
	}
#endif
	assert_success(chmod("first/nested1", 0700));
	assert_success(os_stat("first/nested1", &src));
#endif

	cmd_group_begin("undo msg");

	assert_non_null(ops = ops_alloc(op, 0, "merge", ".", "."));
	ops->crp = CRP_OVERWRITE_ALL;
	if(op == OP_MOVEF)
	{
		assert_success(merge_dirs("first", "second", ops));
	}
	else
	{
#ifndef _WIN32
		if(!cfg.use_system_calls)
		{
			assert_success(
					perform_operation(op, ops, NULL, "first/nested1", "second/"));
		}
		else
#endif
		{
			assert_success(perform_operation(op, ops, NULL, "first", "second"));
		}
	}
	ops_free(ops);

	cmd_group_end();

#ifndef _WIN32
	{
		assert_success(os_stat("second/nested1", &dst));
#ifndef HAVE_STRUCT_STAT_ST_MTIM
#define st_atim st_atime
#define st_mtim st_mtime
#endif
		assert_success(memcmp(&src.st_atim, &dst.st_atim, sizeof(src.st_atim)));
		assert_success(memcmp(&src.st_mtim, &dst.st_mtim, sizeof(src.st_mtim)));
		assert_success(memcmp(&src.st_mode, &dst.st_mode, sizeof(src.st_mode)));
	}
#endif

	assert_true(file_exists("second/nested1/nested2/file"));

	assert_success(unlink("second/nested1/nested2/file"));
	assert_success(rmdir("second/nested1/nested2"));
	assert_success(rmdir("second/nested1"));
	assert_success(rmdir("second"));
}
Exemplo n.º 25
0
/* perform_operation() interface adaptor for the undo unit. */
static int
undo_perform_func(OPS op, void *data, const char src[], const char dst[])
{
	return perform_operation(op, NULL, data, src, dst);
}
Exemplo n.º 26
0
int
example_syscall(struct credential *cred, int index, int op)
{
	/*
	 * Entering the system call should instantiate automata:
	 *
	 * CHECK: [CALE] example_syscall
         * CHECK: sunrise
	 */

	struct object *o;

	/*
	 * get_object() calls hold(), which should be reflected in two automata
	 * (one which cares about entry and the other, exit):
	 *
	 * CHECK: [CALE] hold
	 * CHECK: new  [[A0I0:[0-9]+]]: [[INIT:[0-9]+:0x0]] ('[[A0:.*]]')
	 * CHECK: clone [[A0I0]]:[[INIT]] -> [[A0I1:[0-9]+]]:[[HOLD:[0-9]+:0x1]]
	 * CHECK: [RETE] hold
	 * CHECK: new  [[A1I0:[0-9]+]]: [[INIT:[0-9]+:0x0]] ('[[A1:.*]]')
	 * CHECK: clone [[A1I0]]:[[INIT]] -> [[A1I1:[0-9]+]]:[[HOLD:[0-9]+:0x1]]
	 */
	int error = get_object(index, &o);
	if (error != 0)
		return (error);

	/*
	 * CHECK: [CALE] hold
	 * CHECK: clone [[A0I0]]:[[INIT]] -> [[A0I2:[0-9]+]]:[[HOLD:[0-9]+:0x1]]
	 * CHECK: [RETE] hold
	 * CHECK: clone [[A1I0]]:[[INIT]] -> [[A1I2:[0-9]+]]:[[HOLD:[0-9]+:0x1]]
	 */
	error = get_object(index + 1, &o);
	if (error != 0)
		return (error);

	/*
	 * perform_operation() contains all NOW events:
	 *
	 * CHECK: [ASRT] automaton 0
	 * CHECK: update [[A0I2]]: [[HOLD]]->[[NOW:[0-9]+:0x1]]
	 * CHECK: [ASRT] automaton 1
	 * CHECK: update [[A1I2]]: [[HOLD]]->[[NOW:[0-9]+:0x1]]
	 */
	return perform_operation(op, o);

	/*
	 * On leaving the assertion scope, we should be cleaning up:
	 *
	 * CHECK: [RETE] example_syscall
         *
         * There should only be one (shared) sunset event:
         * CHECK: sunset
         * CHECK-NOT: sunset
	 *
	 * CHECK: update [[A0I0]]: [[INIT]]->[[DONE:[0-9]+:0x0]]
	 * CHECK: pass '[[A0]]': [[A0I0]]
	 * CHECK: update [[A0I1]]: [[HOLD]]->[[DONE:[0-9]+:0x0]]
	 * CHECK: pass '[[A0]]': [[A0I1]]
	 * CHECK: update [[A0I2]]: [[NOW]]->[[DONE:[0-9]+:0x0]]
	 * CHECK: pass '[[A0]]': [[A0I2]]
	 * CHECK: tesla_class_reset [[A0]]
	 *
	 * CHECK: update [[A1I0]]: [[INIT]]->[[DONE:[0-9]+:0x0]]
	 * CHECK: pass '[[A1]]': [[A1I0]]
	 * CHECK: update [[A1I1]]: [[HOLD]]->[[DONE:[0-9]+:0x0]]
	 * CHECK: pass '[[A1]]': [[A1I1]]
	 * CHECK: update [[A1I2]]: [[NOW]]->[[DONE:[0-9]+:0x0]]
	 * CHECK: pass '[[A1]]': [[A1I2]]
	 * CHECK: tesla_class_reset [[A1]]
	 */
}
Exemplo n.º 27
0
int main(int argc, char **argv)
{
	unsigned int *input_matrices[INPUT_SIZE];
	unsigned int *output_matrices[GRAPH_COLS];
	unsigned int i, j;
	unsigned int begin_input, end_input;
	unsigned int rows, cols;

	int r = 0;
	int has_failed;

	struct timeval start_time, end_time;
	unsigned long start_us, end_us, total_time = 0;

	struct device_info device_info;

        if (argc != 3) {
                fprintf(stderr, "Usage: %s rows cols\n", argv[0]);
                return -1;
        }

        rows = (unsigned int)atoi(argv[1]);
        cols = (unsigned int)atoi(argv[2]);

        /* generate identity matrices */
        for (i = 0; i < INPUT_SIZE; i++) {
                if ((input_matrices[i] = (unsigned int *)malloc(rows * cols *
                 sizeof(unsigned int))) == NULL) {
                        fprintf(stderr, "Out of memory error.\n");

                        for (j = 0; j < i; j++)
                                free(input_matrices[i]);

                        return -1;
                }

                for (j = 0; j < rows * cols; j++)
                        input_matrices[i][j] = 1;
        }

	/*
        if (madd_gpu_init(&device_info)) {
                for (i = 0; i < INPUT_SIZE; i++)
                        free(input_matrices[i]);

                return -1;
        }
	*/

	begin_input = 0;
	end_input = GRAPH_ROWS + 1;

	/* Each column in the graph represents a parallel execution path. */
	for (i = 0; i < GRAPH_COLS; i++) {
		gettimeofday(&start_time, NULL);

		output_matrices[i] = perform_operation(&device_info,
		 input_matrices, begin_input, end_input, rows, cols, &r);

		gettimeofday(&end_time, NULL);

		if (r) {
			for (j = 0; j < INPUT_SIZE; j++)
				free(input_matrices[j]);

			for (j = 0; j < i; j++)
				free(output_matrices[j]);

			return r;
		}

		start_us = (unsigned long)start_time.tv_sec * 1000000 + 
		 (unsigned long)start_time.tv_usec;
		end_us = (unsigned long)end_time.tv_sec * 1000000 +
		 (unsigned long)end_time.tv_usec;

		total_time += end_us - start_us;

		begin_input = end_input;
		end_input += GRAPH_ROWS + 1;
	}

	/*
	if (madd_gpu_close(&device_info)) {
		for (i = 0; i < INPUT_SIZE; i++)
			free(input_matrices[i]);

		for (i = 0; i < GRAPH_COLS; i++)
			free(output_matrices[i]);

		return -1;
	}
	*/

	has_failed = 0;

	/* Test output matrices */
	for (i = 0; i < GRAPH_COLS && !has_failed; i++) {
		for (j = 0; j < rows * cols && !has_failed; j++) {
			if (output_matrices[i][j] != EXPECTED_SUM) {
				printf("output_matrix[%u][%u] was %u, but \\"
				 " expected %u\n", i, j, output_matrices[i][j],
				 EXPECTED_SUM);

				has_failed = 1;
			}
		}
	}

	printf("Test %s.\n", has_failed ? "failed" : "passed");
	printf("Running time of rectangle: %lu microseconds\n", total_time);

	for (i = 0; i < INPUT_SIZE; i++)
		free(input_matrices[i]);

	for (i = 0; i < GRAPH_COLS; i++)
		free(output_matrices[i]);

	return 0;
}
Exemplo n.º 28
0
int exec_cmd(struct command_t *cmd) {

    int arg1, arg2;

    if (!number(cmd->arguments[0]) && !number(cmd->arguments[1]) && !supported_operation(cmd->operation)) {
        cmd->success = 0;
        return -4;
    }

    if (supported_operation(cmd->operation)) {
        if (
            (strlen(cmd->operation) < 2) &&
            (strlen(cmd->arguments[0]) <= 0 || strlen(cmd->arguments[1]) <= 0) &&
            (strcmp(cmd->operation, "!") != 0)
        ) {
            cmd->success = 0;
            return -2;
        }

        if (
            (strlen(cmd->operation) >= 2) &&
            (strlen(cmd->arguments[0]) > 0 && strlen(cmd->arguments[1]) > 0)
        ) {
            cmd->success = 0;
            return -2;
        }

        if ((!number(cmd->arguments[0]) || !number(cmd->arguments[1])) &&
                strcmp(cmd->operation, "++") != 0 &&
                strcmp(cmd->operation, "!") != 0
           ) {
            cmd->success = 0;
            return -3;
        }

        if (strcmp(cmd->operation, "++") == 0 && number(cmd->arguments[1]) && strlen(cmd->arguments[0]) <= 0) {
            cmd->success = 0;
            return -4;
        }

        sscanf(cmd->arguments[0], "%d", &arg1);
        sscanf(cmd->arguments[1], "%d", &arg2);

        if (strcmp(cmd->operation, "/") == 0 && arg2 == 0) {
            cmd->success = 0;
            return -5;
        }

        cmd->result = perform_operation(arg1, arg2, cmd->operation);

        if (cmd->result == 42) {
            cmd->success = 1;
            return -42;
        }

    } else {
        cmd->success = 0;
        return -1;
    }
    cmd->success = 1;
    return 0;
}