Ejemplo n.º 1
0
END_TEST

START_TEST (test_perform_action)
    {
        // The current board
        int board[16] = {2, 4, 0, 0,
                         0, 0, 8, 0,
                         0, 0, 0, 0,
                         0, 0, 0, 0};

        // After a move to the left
        int left[16] = {2, 4, 0, 0,
                        8, 0, 0, 0,
                        0, 0, 0, 0,
                        0, 0, 0, 0};

        // After a move to the right
        int right[16] = {0, 0, 2, 4,
                         0, 0, 0, 8,
                         0, 0, 0, 0,
                         0, 0, 0, 0};

        // After a move downwards
        int down[16] = {0, 0, 0, 0,
                        0, 0, 0, 0,
                        0, 0, 0, 0,
                        2, 4, 8, 0};

        // After a move upwards
        int up[16] = {2, 4, 8, 0,
                      0, 0, 0, 0,
                      0, 0, 0, 0,
                      0, 0, 0, 0};

        int* new_board_0 = perform_action(0, board);

        for (int i = 0; i < 16; i++) {
            ck_assert_int_eq(left[i], new_board_0[i]);
        }

        int* new_board_2 = perform_action(2, board);

        for (int i = 0; i < 16; i++) {
            ck_assert_int_eq(right[i], new_board_2[i]);
        }

        int* new_board_3 = perform_action(3, board);

        for (int i = 0; i < 16; i++) {
            ck_assert_int_eq(down[i], new_board_3[i]);
        }

        int* new_board_1 = perform_action(1, board);

        for (int i = 0; i < 16; i++) {
            ck_assert_int_eq(up[i], new_board_1[i]);
        }

    }
Ejemplo n.º 2
0
Archivo: chou.c Proyecto: mudchina/fy4
int wieldblade()
{
command("wield sword");
perform_action("dodge.tianwaifeixian");
command("unwield sword");
return 1;
}  
Ejemplo n.º 3
0
int wieldblade()
{
command("wield piece");
perform_action("throwing.tanzhijinghun");
command("unwield piece");
return 1;
}
Ejemplo n.º 4
0
int auto_perform()
{
        object target = select_opponent();

        if( !objectp(target) )  return 0;

        return perform_action("finger.fuxue");
}
Ejemplo n.º 5
0
/**
 * eufi_apply_flatpak_ref_actions:
 * @installation: a #FlatpakInstallation
 * @state_counter_path: (type filename): path to the counter that records what
 *    actions have been applied
 * @actions: (element-type EuuFlatpakRemoteRefAction): actions to apply
 * @mode: the #EosUpdaterInstallerMode
 * @flags: any #EosUpdaterInstallerFlags
 * @error: return location for a #GError, or %NULL
 *
 * Apply the actions @actions, and update the state counter at
 * @state_counter_path to the last successfully applied action. The actions are
 * only actually performed if @mode is set to %EU_INSTALLER_MODE_PERFORM.
 *
 * Returns: %TRUE on success, %FALSE otherwise
 */
gboolean
eufi_apply_flatpak_ref_actions (FlatpakInstallation       *installation,
                                const gchar               *state_counter_path,
                                GPtrArray                 *actions,
                                EosUpdaterInstallerMode    mode,
                                EosUpdaterInstallerFlags   flags,
                                GError                   **error)
{
  gsize i;
  g_autoptr(GHashTable) new_progresses = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);

  g_return_val_if_fail (FLATPAK_IS_INSTALLATION (installation), FALSE);
  g_return_val_if_fail (state_counter_path != NULL, FALSE);
  g_return_val_if_fail (actions != NULL, FALSE);
  g_return_val_if_fail (mode != EU_INSTALLER_MODE_CHECK, FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  for (i = 0; i < actions->len; ++i)
    {
      EuuFlatpakRemoteRefAction *pending_action = g_ptr_array_index (actions, i);
      const gchar *source = pending_action->source;
      gboolean is_dependency = (pending_action->flags & EUU_FLATPAK_REMOTE_REF_ACTION_FLAG_IS_DEPENDENCY) != 0;

      /* Dependencies should not be passed through this function - they
       * were meant to be deployed earlier. Uninstall dependencies will
       * be handled implicitly. Allow them if we’re running
       * `eos-updater-flatpak-installer -mode deploy --pull` manually though. */
      g_assert (!is_dependency || flags & EU_INSTALLER_FLAGS_ALSO_PULL);

      /* Only perform actions if we’re in the "perform" mode. Otherwise
       * we just pretend to perform actions and update the counter
       * accordingly */
      if (mode == EU_INSTALLER_MODE_PERFORM &&
          !perform_action (installation, pending_action, flags, error))
        {
          /* If we fail, we should still update the state of the counter
           * to the last successful one before we get out. This is to ensure
           * that we don’t perform the same action again next time. */
          update_counter_complain_on_error (source,
                                            state_counter_path,
                                            new_progresses);
          return FALSE;
        }

      g_hash_table_replace (new_progresses,
                            (gpointer) source,
                            GINT_TO_POINTER (pending_action->serial));
    }

    /* Once we’re done, update the state of the counter, but bail out
     * if it fails */
    if (!update_counter (state_counter_path,
                         new_progresses,
                         error))
      return FALSE;

  return TRUE;
}
Ejemplo n.º 6
0
static gboolean
my_atk_action_do_action (AtkAction *action, gint i)
{
  g_return_val_if_fail (MY_IS_ATK_ACTION (action), NULL);

  perform_action (ATK_OBJECT (action));

  return FALSE;
}
Ejemplo n.º 7
0
int auto_perform()
{
        object me = this_object();
        object target = me->select_opponent();
        object weapon = me->query_temp("weapon");

        if( !(int)me->query_temp("shielded") && ( me->query("neili") > 600 ) )
           return exert_function("shield");

        if ( objectp(weapon) && weapon->query("skill_type") == "blade")
           return perform_action("blade.shendao");

        if ( objectp(weapon) && weapon->query("skill_type") == "hammer")
           return perform_action("hammer.riyue");
 
        if ( !objectp(target)
          || !random( (int)me->query("combat_exp") * 2
                   / (int)target->query("combat_exp") + 1) ) return 0;
        return perform_action("strike.fen");
}
Ejemplo n.º 8
0
struct BotThinkFunc* botRun(struct BotState* state){
	static int runNextPulse = 0;
	static const int runPulseTimeout = 25;

	if( runNextPulse < qbTickCount() ) {
		qbLog("heartbeat");
		//memset(&state->gs, 0, sizeof(state->gs));
		qbGetGameState(&state->gs);
		if(!begun)
		{
			learner.set_num_features(22);
			learner.set_eta(0.1);
			learner.init(0.1, 0.3, 0.0);
			qbLog("Before tick: %d", qbTickCount());
			getPlayerInfo(&state->gs, state->name);
			getItemIndices(state->gs);
			qbMovementOrder(zero_a, zero_v, 0);
			qbLog("After tick: %d", qbTickCount());
			begun = true;
		}
		qbLog("Before time: %d", qbTickCount());
		//parseItems(state->gs);
		getClosestEntities(state->gs);
		qbLog("getting next action");
		int action = learner.learning_step(&state->gs, closest_entities, get_reward(state->gs));
		if(state->gs.player.health < 0)
		{
			qbMovementOrder(zero_a, forward_v, 1);
			getPlayerInfo(&state->gs, state->name);
			getItemIndices(state->gs);
			state->gs.player.angle = 0.0;
			num_deaths++;
		}
		else
		{
			perform_action(&state->gs, action);
		}
		//qbMovementOrder(zero_a, forward_v, 1);
		//LogPlayerInfo(state->gs);
		qbLog("After time: %d", qbTickCount());
		//populateItemList(state->gs);
		//parseEntities(state->gs);
		//runTowardEntity(1, state->gs);
		runNextPulse = qbTickCount() + runPulseTimeout;
	}
/*
#ifdef WIN32
	Sleep(QB_MIN_FRAMETIME);
#else
	usleep(QB_MIN_FRAMETIME * 1000);
#endif*/
	return NULL;
}
Ejemplo n.º 9
0
void PlayerInst::perform_queued_actions(GameState* gs) {
	perf_timer_begin(FUNCNAME);
	GameSettings& settings = gs->game_settings();

	if (settings.saving_to_action_file()) {
		save_actions(gs, queued_actions);
	}

	for (int i = 0; i < queued_actions.size(); i++) {
		perform_action(gs, queued_actions[i]);
	}
	queued_actions.clear();
	actions_set_for_turn = false;
	perf_timer_end(FUNCNAME);
}
int Dialog::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QDialog::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: setInteger(); break;
        case 1: setText(); break;
        case 2: perform_action(); break;
        default: ;
        }
        _id -= 3;
    }
    return _id;
}
void pa_policy_context_variable_commit(struct userdata *u)
{
    union pa_policy_context_action *action;
    char *value;

    pa_assert(u);
    pa_assert(u->context);

    while (u->context->variable_change_count) {
        u->context->variable_change_count--;

        action = u->context->variable_change[u->context->variable_change_count].action;
        value  = u->context->variable_change[u->context->variable_change_count].value;

        if (!perform_action(u, action, value))
            pa_log("Failed to perform action for value %s", value);
        pa_xfree(value);
    }
}
Ejemplo n.º 12
0
static void host_really_activate(AIO_SLOT *slot)
{
  AIO_SLOT *saved_slot = cur_slot;
  HOST_SLOT *hs = (HOST_SLOT *)slot;

  log_write(LL_MSG, "Activating new host connection");
  slot->type = TYPE_HOST_ACTIVE_SLOT;
  s_host_slot = slot;

  write_active_file();
  perform_action("host_activate");

  /* Allocate the framebuffer or extend its dimensions if necessary */
  if (!alloc_framebuffer(hs->fb_width, hs->fb_height)) {
    aio_close(1);
    return;
  }

  /* Set default desktop geometry for new client connections */
  g_screen_info.width = hs->fb_width;
  g_screen_info.height = hs->fb_height;

  /* If requested, open file to save this session and write the header */
  fbs_open_file(hs->fb_width, hs->fb_height);

  cur_slot = slot;

  /* Reset zlib streams in the Tight decoder */
  reset_tight_streams();

  /* Request initial screen contents */
  log_write(LL_DETAIL, "Requesting full framebuffer update");
  request_update(0);
  aio_setread(rf_host_msg, NULL, 1);

  /* Notify clients about desktop geometry change */
  aio_walk_slots(fn_host_pass_newfbsize, TYPE_CL_SLOT);

  cur_slot = saved_slot;
}
Ejemplo n.º 13
0
int main(){
  int d1,n,n_file;
  n = nondet_int(); //non_d directory
  init_fs(); //Init sample file-system

  //Assume to be in the allowed directory range
  __CPROVER_assume(n >= 0 && n < MAX_DIRS);
  // d1 = open_dir(n,"test");
  // assert(d1<0);


  ////////////////////////////////////////////////////////
  //A file can only be read or written when it is open  //
  ////////////////////////////////////////////////////////
  n_file = open_file(0, "test"); //open file
  assert(n_file == 0);
  // n_file = open_file(1, "test"); //open file
  // assert(n_file > 0);
  // n_file = open_file(2, "test"); //open file
  // assert(n_file > 0);
  // n_file = open_file(3, "test"); //open file
  // assert(n_file > 0);
  
  // if((file_status[n_file] & ENTRY_USED)){ //check if file is open
  //     int w1 = write_file(n_file, 0, 11, "hello world"); //write
  //     assert(w1 == 11); //Write should success file is open
  // }else{
  //     int w1 = write_file(n_file, 0, 11, "hello world"); //write
  //     assert(w1<0); //Write should fail file is closed
  // }
  // assert((dir_status[n] & ENTRY_USED) == (file_status[n] & ENTRY_USED)); //file is open

  //Assume to be in the allowed file range
  __CPROVER_assume(n_file >= 0 && n_file < MAX_FILES);

   perform_action(2);
  
}
Ejemplo n.º 14
0
int listening_function() {

    int ds_sock;
    int port = 4446;
    int length_inc;
    int ds_acc;

    struct sockaddr_in addr,inc;

    ds_sock = socket(AF_INET,SOCK_STREAM,0);

    addr.sin_family = AF_INET;
    addr.sin_port = htons(port);
    addr.sin_addr.s_addr = INADDR_ANY;

    int length_addr = sizeof(addr);

    if(bind(ds_sock,(struct sockaddr *)&addr,length_addr)==-1) {
        perror("Binding error");
        exit(1);
    }
    if(listen(ds_sock,BACKLOG)==-1) {
        perror("Listening error");
        exit(1);
    }
    length_inc = sizeof(inc);

    while(1) {
        while((ds_acc = accept(ds_sock,(struct sockaddr *)&inc, &length_inc))==-1 );
        printf(">>Connected to socket %d \n",ds_acc);
        alarm_flag = 0;
        alarm(5);
        perform_action(ds_acc);
        alarm(0);
        check_res_status();
    }
}
/* force_state can be -1  - do not force , 0 force inactive, 1 force active */
static int perform_activity_action(pa_sink *sink, struct pa_policy_activity_variable *var, int force_state) {
    struct pa_policy_context_rule     *rule;
    union pa_policy_context_action    *actn;
    int                                is_opened;

    pa_assert(sink);

    if ((force_state != -1 && force_state == 1) ||
        (force_state == -1 && PA_SINK_IS_OPENED(pa_sink_get_state(sink)))) {
        rule = var->active_rules;
        is_opened = 1;
    } else {
        rule = var->inactive_rules;
        is_opened = 0;
    }

    for ( ;  rule != NULL;  rule = rule->next) {
        if (rule->match.method(sink->name, &rule->match.arg)) {

            if (force_state == -1 && var->sink_opened != -1 && var->sink_opened == is_opened) {
                pa_log_debug("Already executed actions for state change, skip.");
                return 1;
            }

            var->sink_opened = is_opened;

            for (actn = rule->actions; actn; actn = actn->any.next)
            {
                if (!perform_action(var->userdata, actn, NULL))
                    pa_log("Failed to perform activity action.");
            }
        }
    }

    return 1;
}
Ejemplo n.º 16
0
Archivo: zinject.c Proyecto: RJVB/zfs
int
main(int argc, char **argv)
{
	int c;
	char *range = NULL;
	char *cancel = NULL;
	char *end;
	char *raw = NULL;
	char *device = NULL;
	int level = 0;
	int quiet = 0;
	int error = 0;
	int domount = 0;
	int io_type = ZIO_TYPES;
	int action = VDEV_STATE_UNKNOWN;
	err_type_t type = TYPE_INVAL;
	err_type_t label = TYPE_INVAL;
	zinject_record_t record = { 0 };
	char pool[MAXNAMELEN];
	char dataset[MAXNAMELEN];
	zfs_handle_t *zhp = NULL;
	int nowrites = 0;
	int dur_txg = 0;
	int dur_secs = 0;
	int ret;
	int flags = 0;

	if ((g_zfs = libzfs_init()) == NULL)
		return (1);

	libzfs_print_on_error(g_zfs, B_TRUE);

	if ((zfs_fd = open(ZFS_DEV, O_RDWR)) < 0) {
		(void) fprintf(stderr, "failed to open ZFS device\n");
		return (1);
	}

	if (argc == 1) {
		/*
		 * No arguments.  Print the available handlers.  If there are no
		 * available handlers, direct the user to '-h' for help
		 * information.
		 */
		if (print_all_handlers() == 0) {
			(void) printf("No handlers registered.\n");
			(void) printf("Run 'zinject -h' for usage "
			    "information.\n");
		}

		return (0);
	}

	while ((c = getopt(argc, argv,
	    ":aA:b:d:D:f:Fg:qhIc:t:T:l:mr:s:e:uL:p:")) != -1) {
		switch (c) {
		case 'a':
			flags |= ZINJECT_FLUSH_ARC;
			break;
		case 'A':
			if (strcasecmp(optarg, "degrade") == 0) {
				action = VDEV_STATE_DEGRADED;
			} else if (strcasecmp(optarg, "fault") == 0) {
				action = VDEV_STATE_FAULTED;
			} else {
				(void) fprintf(stderr, "invalid action '%s': "
				    "must be 'degrade' or 'fault'\n", optarg);
				usage();
				return (1);
			}
			break;
		case 'b':
			raw = optarg;
			break;
		case 'c':
			cancel = optarg;
			break;
		case 'd':
			device = optarg;
			break;
		case 'D':
			errno = 0;
			record.zi_timer = strtoull(optarg, &end, 10);
			if (errno != 0 || *end != '\0') {
				(void) fprintf(stderr, "invalid i/o delay "
				    "value: '%s'\n", optarg);
				usage();
				return (1);
			}
			break;
		case 'e':
			if (strcasecmp(optarg, "io") == 0) {
				error = EIO;
			} else if (strcasecmp(optarg, "checksum") == 0) {
				error = ECKSUM;
			} else if (strcasecmp(optarg, "nxio") == 0) {
				error = ENXIO;
			} else if (strcasecmp(optarg, "dtl") == 0) {
				error = ECHILD;
			} else {
				(void) fprintf(stderr, "invalid error type "
				    "'%s': must be 'io', 'checksum' or "
				    "'nxio'\n", optarg);
				usage();
				return (1);
			}
			break;
		case 'f':
			record.zi_freq = atoi(optarg);
			if (record.zi_freq < 1 || record.zi_freq > 100) {
				(void) fprintf(stderr, "frequency range must "
				    "be in the range (0, 100]\n");
				return (1);
			}
			break;
		case 'F':
			record.zi_failfast = B_TRUE;
			break;
		case 'g':
			dur_txg = 1;
			record.zi_duration = (int)strtol(optarg, &end, 10);
			if (record.zi_duration <= 0 || *end != '\0') {
				(void) fprintf(stderr, "invalid duration '%s': "
				    "must be a positive integer\n", optarg);
				usage();
				return (1);
			}
			/* store duration of txgs as its negative */
			record.zi_duration *= -1;
			break;
		case 'h':
			usage();
			return (0);
		case 'I':
			/* default duration, if one hasn't yet been defined */
			nowrites = 1;
			if (dur_secs == 0 && dur_txg == 0)
				record.zi_duration = 30;
			break;
		case 'l':
			level = (int)strtol(optarg, &end, 10);
			if (*end != '\0') {
				(void) fprintf(stderr, "invalid level '%s': "
				    "must be an integer\n", optarg);
				usage();
				return (1);
			}
			break;
		case 'm':
			domount = 1;
			break;
		case 'p':
			(void) strlcpy(record.zi_func, optarg,
			    sizeof (record.zi_func));
			record.zi_cmd = ZINJECT_PANIC;
			break;
		case 'q':
			quiet = 1;
			break;
		case 'r':
			range = optarg;
			break;
		case 's':
			dur_secs = 1;
			record.zi_duration = (int)strtol(optarg, &end, 10);
			if (record.zi_duration <= 0 || *end != '\0') {
				(void) fprintf(stderr, "invalid duration '%s': "
				    "must be a positive integer\n", optarg);
				usage();
				return (1);
			}
			break;
		case 'T':
			if (strcasecmp(optarg, "read") == 0) {
				io_type = ZIO_TYPE_READ;
			} else if (strcasecmp(optarg, "write") == 0) {
				io_type = ZIO_TYPE_WRITE;
			} else if (strcasecmp(optarg, "free") == 0) {
				io_type = ZIO_TYPE_FREE;
			} else if (strcasecmp(optarg, "claim") == 0) {
				io_type = ZIO_TYPE_CLAIM;
			} else if (strcasecmp(optarg, "all") == 0) {
				io_type = ZIO_TYPES;
			} else {
				(void) fprintf(stderr, "invalid I/O type "
				    "'%s': must be 'read', 'write', 'free', "
				    "'claim' or 'all'\n", optarg);
				usage();
				return (1);
			}
			break;
		case 't':
			if ((type = name_to_type(optarg)) == TYPE_INVAL &&
			    !MOS_TYPE(type)) {
				(void) fprintf(stderr, "invalid type '%s'\n",
				    optarg);
				usage();
				return (1);
			}
			break;
		case 'u':
			flags |= ZINJECT_UNLOAD_SPA;
			break;
		case 'L':
			if ((label = name_to_type(optarg)) == TYPE_INVAL &&
			    !LABEL_TYPE(type)) {
				(void) fprintf(stderr, "invalid label type "
				    "'%s'\n", optarg);
				usage();
				return (1);
			}
			break;
		case ':':
			(void) fprintf(stderr, "option -%c requires an "
			    "operand\n", optopt);
			usage();
			return (1);
		case '?':
			(void) fprintf(stderr, "invalid option '%c'\n",
			    optopt);
			usage();
			return (2);
		}
	}

	argc -= optind;
	argv += optind;

	if (record.zi_duration != 0)
		record.zi_cmd = ZINJECT_IGNORED_WRITES;

	if (cancel != NULL) {
		/*
		 * '-c' is invalid with any other options.
		 */
		if (raw != NULL || range != NULL || type != TYPE_INVAL ||
		    level != 0 || record.zi_cmd != ZINJECT_UNINITIALIZED) {
			(void) fprintf(stderr, "cancel (-c) incompatible with "
			    "any other options\n");
			usage();
			return (2);
		}
		if (argc != 0) {
			(void) fprintf(stderr, "extraneous argument to '-c'\n");
			usage();
			return (2);
		}

		if (strcmp(cancel, "all") == 0) {
			return (cancel_all_handlers());
		} else {
			int id = (int)strtol(cancel, &end, 10);
			if (*end != '\0') {
				(void) fprintf(stderr, "invalid handle id '%s':"
				    " must be an integer or 'all'\n", cancel);
				usage();
				return (1);
			}
			return (cancel_handler(id));
		}
	}

	if (device != NULL) {
		/*
		 * Device (-d) injection uses a completely different mechanism
		 * for doing injection, so handle it separately here.
		 */
		if (raw != NULL || range != NULL || type != TYPE_INVAL ||
		    level != 0 || record.zi_cmd != ZINJECT_UNINITIALIZED) {
			(void) fprintf(stderr, "device (-d) incompatible with "
			    "data error injection\n");
			usage();
			return (2);
		}

		if (argc != 1) {
			(void) fprintf(stderr, "device (-d) injection requires "
			    "a single pool name\n");
			usage();
			return (2);
		}

		(void) strcpy(pool, argv[0]);
		dataset[0] = '\0';

		if (error == ECKSUM) {
			(void) fprintf(stderr, "device error type must be "
			    "'io' or 'nxio'\n");
			return (1);
		}

		record.zi_iotype = io_type;
		if (translate_device(pool, device, label, &record) != 0)
			return (1);
		if (!error)
			error = ENXIO;

		if (action != VDEV_STATE_UNKNOWN)
			return (perform_action(pool, &record, action));

	} else if (raw != NULL) {
		if (range != NULL || type != TYPE_INVAL || level != 0 ||
		    record.zi_cmd != ZINJECT_UNINITIALIZED) {
			(void) fprintf(stderr, "raw (-b) format with "
			    "any other options\n");
			usage();
			return (2);
		}

		if (argc != 1) {
			(void) fprintf(stderr, "raw (-b) format expects a "
			    "single pool name\n");
			usage();
			return (2);
		}

		(void) strcpy(pool, argv[0]);
		dataset[0] = '\0';

		if (error == ENXIO) {
			(void) fprintf(stderr, "data error type must be "
			    "'checksum' or 'io'\n");
			return (1);
		}

		record.zi_cmd = ZINJECT_DATA_FAULT;
		if (translate_raw(raw, &record) != 0)
			return (1);
		if (!error)
			error = EIO;
	} else if (record.zi_cmd == ZINJECT_PANIC) {
		if (raw != NULL || range != NULL || type != TYPE_INVAL ||
		    level != 0 || device != NULL) {
			(void) fprintf(stderr, "panic (-p) incompatible with "
			    "other options\n");
			usage();
			return (2);
		}

		if (argc < 1 || argc > 2) {
			(void) fprintf(stderr, "panic (-p) injection requires "
			    "a single pool name and an optional id\n");
			usage();
			return (2);
		}

		(void) strcpy(pool, argv[0]);
		if (argv[1] != NULL)
			record.zi_type = atoi(argv[1]);
		dataset[0] = '\0';
	} else if (record.zi_cmd == ZINJECT_IGNORED_WRITES) {
		if (nowrites == 0) {
			(void) fprintf(stderr, "-s or -g meaningless "
			    "without -I (ignore writes)\n");
			usage();
			return (2);
		} else if (dur_secs && dur_txg) {
			(void) fprintf(stderr, "choose a duration either "
			    "in seconds (-s) or a number of txgs (-g) "
			    "but not both\n");
			usage();
			return (2);
		} else if (argc != 1) {
			(void) fprintf(stderr, "ignore writes (-I) "
			    "injection requires a single pool name\n");
			usage();
			return (2);
		}

		(void) strcpy(pool, argv[0]);
		dataset[0] = '\0';
	} else if (type == TYPE_INVAL) {
		if (flags == 0) {
			(void) fprintf(stderr, "at least one of '-b', '-d', "
			    "'-t', '-a', '-p', '-I' or '-u' "
			    "must be specified\n");
			usage();
			return (2);
		}

		if (argc == 1 && (flags & ZINJECT_UNLOAD_SPA)) {
			(void) strcpy(pool, argv[0]);
			dataset[0] = '\0';
		} else if (argc != 0) {
			(void) fprintf(stderr, "extraneous argument for "
			    "'-f'\n");
			usage();
			return (2);
		}

		flags |= ZINJECT_NULL;
	} else {
		if (argc != 1) {
			(void) fprintf(stderr, "missing object\n");
			usage();
			return (2);
		}

		if (error == ENXIO) {
			(void) fprintf(stderr, "data error type must be "
			    "'checksum' or 'io'\n");
			return (1);
		}

		record.zi_cmd = ZINJECT_DATA_FAULT;
		if (translate_record(type, argv[0], range, level, &record, pool,
		    dataset) != 0)
			return (1);
		if (!error)
			error = EIO;
	}

	/*
	 * If this is pool-wide metadata, unmount everything.  The ioctl() will
	 * unload the pool, so that we trigger spa-wide reopen of metadata next
	 * time we access the pool.
	 */
	if (dataset[0] != '\0' && domount) {
		if ((zhp = zfs_open(g_zfs, dataset, ZFS_TYPE_DATASET)) == NULL)
			return (1);
		if (zfs_unmount(zhp, NULL, 0) != 0)
			return (1);
	}

	record.zi_error = error;

	ret = register_handler(pool, flags, &record, quiet);

	if (dataset[0] != '\0' && domount)
		ret = (zfs_mount(zhp, NULL, 0) != 0);

	libzfs_fini(g_zfs);

	return (ret);
}
Ejemplo n.º 17
0
int
calc_performance_one_environment(int* chrom)
/* Environment is  randomly generated.  Chrom is run on
 *  environment for NUM_MOVES.  Function returns number of performance points the chromosome
 *  gets. */

{
  int site, move_number, action, performance_points = 0; 
  int n_row, n_column, s_row, s_column, e_row, e_column, w_row, w_column, c_row, c_column; 
  double robby_text_row_coord, robby_text_column_coord;  /* Where to draw robby */ 
  int state, smaller_state; 

  init_environment(); 

  /* Keep going for NUM_MOVES.  Performance is how many cans were
   * collected. */ 


  for (move_number = 1; move_number <= NUM_MOVES; move_number++) {

#if DEBUG
    printf("Move: %d\n", move_number); 
#endif

    state = 0; 

    /* Calculate integer representing state of neighborhood NSEWC.  It is in [0, 242]. 
       The contents of each of these five cells is represented by:  EMPTY = 0, CAN = 1, WALL = 2 */

    /* NORTH */ 
    n_row = environment[robby_row][robby_column].N_row; 
    n_column = environment[robby_row][robby_column].N_column; 

    if (((n_row < 0) || (n_row >= NUM_ENVIRONMENT_ROWS)) 
	|| ((n_column < 0) || (n_column >= NUM_ENVIRONMENT_COLUMNS))) 
      state = state + NORTH_BASE * WALL ; /* NORTH is a wall */ 
    else 
      if (environment[n_row][n_column].contains_soda_can) 
	state = state + NORTH_BASE * CAN;    /* NORTH cell has a can */ 
      else
	state = state + NORTH_BASE * EMPTY;  /* NORTH cell is empty */ 


#if DEBUG
    printf("After north, state is %d\n", state); 
#endif


    /* SOUTH */ 
    s_row = environment[robby_row][robby_column].S_row; 
    s_column = environment[robby_row][robby_column].S_column; 

    if (((s_row < 0) || (s_row >= NUM_ENVIRONMENT_ROWS)) 
	|| ((s_column < 0) || (s_column >= NUM_ENVIRONMENT_COLUMNS)))   
      state = state + SOUTH_BASE * WALL;     /* SOUTH is a wall */ 

    else 
      if (environment[s_row][s_column].contains_soda_can)
	state = state + SOUTH_BASE * CAN;    /* SOUTH cell has a can */ 
      else
	state = state + SOUTH_BASE * EMPTY;  /* SOUTH cell is empty */ 

#if DEBUG
    printf("After south, state is %d\n", state); 
#endif

    /* EAST */ 
    e_row = environment[robby_row][robby_column].E_row; 
    e_column = environment[robby_row][robby_column].E_column; 

    if (((e_row < 0) || (e_row >= NUM_ENVIRONMENT_ROWS)) 
	|| ((e_column < 0) || (e_column >= NUM_ENVIRONMENT_COLUMNS))) 
      state = state + EAST_BASE * WALL;     /* EAST is a wall */ 
    else 
      if (environment[e_row][e_column].contains_soda_can)
	state = state + EAST_BASE * CAN;    /* EAST cell has a can */ 
      else
	state = state + EAST_BASE * EMPTY;  /* EAST cell is empty */ 

#if DEBUG
    printf("After east, state is %d\n", state); 
#endif

    /* WEST */ 
    w_row = environment[robby_row][robby_column].W_row; 
    w_column = environment[robby_row][robby_column].W_column; 

    if (((w_row < 0) || (w_row >= NUM_ENVIRONMENT_ROWS)) 
	|| ((w_column < 0) || (w_column >= NUM_ENVIRONMENT_COLUMNS))) 
      state = state + WEST_BASE * WALL;     /* WEST is a wall */ 
    else 
      if (environment[w_row][w_column].contains_soda_can)
	state = state + WEST_BASE * CAN;    /* WEST cell has a can */ 
      else
	state = state + WEST_BASE * EMPTY;  /* WEST cell is empty */ 

#if DEBUG
    printf("After west, state is %d\n", state); 
#endif

    /* CENTER */ 
    c_row = environment[robby_row][robby_column].C_row;
    c_column = environment[robby_row][robby_column].C_column; 

    /* Skip test for wall, since center cell is not a wall. */ 

    if (environment[c_row][c_column].contains_soda_can)
      state = state + CAN;    /* CENTER cell has a can */ 
    else
      state = state + EMPTY;  /* CENTER cell is empty */ 

#if DEBUG
    printf("After center, state is %d\n", state); 
#endif

    action = chrom[state]; 

#if DEBUG
    printf("Action is %d\n", action); 
#endif


    /* Perform action corresponding to state */

#if DEBUG
    printf("Before perform action: current performance points: %d\n", performance_points); 
#endif

    performance_points = performance_points + perform_action(action); 
#if DEBUG
    printf("After perform action: current performance points: %d\n", performance_points); 
#endif

  }

#if DEBUG
  printf("Performance: %d\n", performance_points); 
#endif

  return (performance_points); 

}
Ejemplo n.º 18
0
void
do_addr(fcode_env_t *env)
{
	PUSH(DS, 2);
	perform_action(env);
}
Ejemplo n.º 19
0
void
do_set(fcode_env_t *env)
{
	PUSH(DS, 1);
	perform_action(env);
}
Ejemplo n.º 20
0
int perform_action(int action)
{
  /* Perform given action, and return performance points */

  int n_row, n_column, s_row, s_column, e_row, e_column, w_row, w_column, c_row, c_column; 

  int reward, random_action; 

  double r; 

  reward = 0; 

#if DEBUG
  printf("In perform_action with action: %d\n", action); 
#endif

  /* If robby hits a wall, he bounces back to where he was, and loses 10 points.  
   * If robby succeeds in picking up a can, he wins 1 point.  
   * If robby tries to pick up a can in an empty space, he loses 1 point. */ 

  n_row = environment[robby_row][robby_column].N_row; 
  n_column = environment[robby_row][robby_column].N_column; 
  s_row = environment[robby_row][robby_column].S_row; 
  s_column = environment[robby_row][robby_column].S_column; 
  e_row = environment[robby_row][robby_column].E_row; 
  e_column = environment[robby_row][robby_column].E_column; 
  w_row = environment[robby_row][robby_column].W_row; 
  w_column = environment[robby_row][robby_column].W_column; 
  c_row = environment[robby_row][robby_column].C_row;
  c_column = environment[robby_row][robby_column].C_column; 

  switch (action) {

  case MOVE_NORTH: 

#if DEBUG
    printf("Action is NORTH\n"); 
#endif

    if (((n_row < 0) || (n_row >= NUM_ENVIRONMENT_ROWS)) 
	|| ((n_column < 0) || (n_column >= NUM_ENVIRONMENT_COLUMNS)))   /* Wall */ 
      reward = WALL_PENALTY; 
    else
      robby_row = robby_row - 1; 
    break; 

  case MOVE_SOUTH: 

#if DEBUG
    printf("Action is SOUTH\n"); 
#endif

    if (((s_row < 0) || (s_row >= NUM_ENVIRONMENT_ROWS)) 
	|| ((s_column < 0) || (s_column >= NUM_ENVIRONMENT_COLUMNS)))   /* Wall */ 
      reward = WALL_PENALTY; 
    else 
      robby_row = robby_row + 1; 
    break; 

	  
  case MOVE_EAST: 

#if DEBUG
    printf("Action is EAST\n"); 
#endif

    if (((e_row < 0) || (e_row >= NUM_ENVIRONMENT_ROWS)) 
	|| ((e_column < 0) || (e_column >= NUM_ENVIRONMENT_COLUMNS)))   /* Wall */ 
      reward = WALL_PENALTY; 
    else 
      robby_column = robby_column + 1; 
    break; 

  case MOVE_WEST: 

#if DEBUG
    printf("Action is WEST\n"); 
#endif

    if (((w_row < 0) || (w_row >= NUM_ENVIRONMENT_ROWS)) 
	|| ((w_column < 0) || (w_column >= NUM_ENVIRONMENT_COLUMNS)))   /* Wall */ 
      reward = WALL_PENALTY; 
    else 
      robby_column = robby_column - 1; 
    break; 

  case STAY_PUT: 

#if DEBUG
    printf("Action is STAY_PUT\n"); 
#endif
      /* Do nothing */
    break; 

  case PICK_UP: 

#if DEBUG
    printf("Action is PICK_UP\n"); 
#endif

    if (environment[robby_row][robby_column].contains_soda_can) {
      reward = CAN_REWARD; 
      environment[robby_row][robby_column].contains_soda_can = FALSE; 
    }
    else
      reward = CAN_PENALTY; 
    break; 

  case RANDOM_MOVE: 

#if DEBUG
    printf("Action is RANDOM_MOVE\n"); 
#endif
    
    r = knuth_random(); 
    random_action = (int) (r * (MOVE_WEST + 1)); 
    
    /* random_action is 0, 1, 2, or 3 */ 

#if DEBUG 
    printf("Random action: %d\n", random_action); 
    printf("About to call perform_action with that action\n"); 
#endif

    reward = perform_action(random_action); 
    break; 
  }

#if DEBUG
  printf("Reward %d\n", reward); 
#endif

  return(reward); 
}