int btrfs_test_free_space_cache(void)
{
	struct btrfs_block_group_cache *cache;
	int ret;

	test_msg("Running btrfs free space cache tests\n");

	cache = init_test_block_group();
	if (!cache) {
		test_msg("Couldn't run the tests\n");
		return 0;
	}

	ret = test_extents(cache);
	if (ret)
		goto out;
	ret = test_bitmaps(cache);
	if (ret)
		goto out;
	ret = test_bitmaps_and_extents(cache);
	if (ret)
		goto out;
out:
	__btrfs_remove_free_space_cache(cache->free_space_ctl);
	kfree(cache->free_space_ctl);
	kfree(cache);
	test_msg("Free space cache tests finished\n");
	return ret;
}
Esempio n. 2
0
void
test_filters(gboolean not)
{
  LogMessage *msg = log_msg_new_empty();
  FilterExprNode *f = filter_tags_new(NULL);
  guint i;
  GList *l = NULL;

  test_msg("=== filter tests %s===\n", not ? "not " : "");

  for (i = 1; i < FILTER_TAGS; i += 3)
    l = g_list_prepend(l, get_tag_by_id(i));

  filter_tags_add(f, l);
  f->comp = not;

  for (i = 0; i < FILTER_TAGS; i++)
    {
      test_msg("Testing filter, message has tag %d\n", i);
      log_msg_set_tag_by_id(msg, i);

      if (((i % 3 == 1) ^ filter_expr_eval(f, msg)) ^ not)
        test_fail("Failed to match message by tag %d\n", i);

      test_msg("Testing filter, message no tag\n");
      log_msg_clear_tag_by_id(msg, i);
      if (filter_expr_eval(f, msg) ^ not)
        test_fail("Failed to match message with no tags\n");
    }

  filter_expr_unref(f);
  log_msg_unref(msg);
}
int btrfs_test_free_space_tree(void)
{
	test_func_t tests[] = {
		test_empty_block_group,
		test_remove_all,
		test_remove_beginning,
		test_remove_end,
		test_remove_middle,
		test_merge_left,
		test_merge_right,
		test_merge_both,
		test_merge_none,
	};
	int i;

	test_msg("Running free space tree tests\n");
	for (i = 0; i < ARRAY_SIZE(tests); i++) {
		int ret = run_test_both_formats(tests[i]);
		if (ret) {
			test_msg("%pf failed\n", tests[i]);
			return ret;
		}
	}

	return 0;
}
Esempio n. 4
0
static int remove_extent_item(struct btrfs_root *root, u64 bytenr,
			      u64 num_bytes)
{
	struct btrfs_trans_handle trans;
	struct btrfs_key key;
	struct btrfs_path *path;
	int ret;

	btrfs_init_dummy_trans(&trans);

	key.objectid = bytenr;
	key.type = BTRFS_EXTENT_ITEM_KEY;
	key.offset = num_bytes;

	path = btrfs_alloc_path();
	if (!path) {
		test_msg("Couldn't allocate path\n");
		return -ENOMEM;
	}
	path->leave_spinning = 1;

	ret = btrfs_search_slot(&trans, root, &key, path, -1, 1);
	if (ret) {
		test_msg("Didn't find our key %d\n", ret);
		btrfs_free_path(path);
		return ret;
	}
	btrfs_del_item(&trans, root, path);
	btrfs_free_path(path);
	return 0;
}
Esempio n. 5
0
/* Used by test_steal_space_from_bitmap_to_extent(). */
static int check_cache_empty(struct btrfs_block_group_cache *cache)
{
	u64 offset;
	u64 max_extent_size;

	/*
	 * Now lets confirm that there's absolutely no free space left to
	 * allocate.
	 */
	if (cache->free_space_ctl->free_space != 0) {
		test_msg("Cache free space is not 0\n");
		return -EINVAL;
	}

	/* And any allocation request, no matter how small, should fail now. */
	offset = btrfs_find_space_for_alloc(cache, 0, 4096, 0,
					    &max_extent_size);
	if (offset != 0) {
		test_msg("Space allocation did not fail, returned offset: %llu",
			 offset);
		return -EINVAL;
	}

	/* And no extent nor bitmap entries in the cache anymore. */
	return check_num_extents_and_bitmaps(cache, 0, 0);
}
Esempio n. 6
0
int main(int argc, char **argv)
{
	test_init(argc, argv);
	unsigned char *mem;

	test_msg("Alloc huge VMA\n");
	mem = (void *)mmap(NULL, (10L << 30), PROT_READ | PROT_WRITE,
			   MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
	if ((void *)mem == MAP_FAILED) {
		pr_perror("mmap failed");
		return -1;
	}

	mem[4L << 30] = 1;
	mem[8L << 30] = 2;

	test_daemon();
	test_waitsig();

	test_msg("Testing restored data\n");

	if (mem[4L << 30] != 1 || mem[8L << 30] != 2) {
		fail("Data corrupted!\n");
		exit(1);
	}

	pass();

	return 0;
}
Esempio n. 7
0
void
test_msg_tags()
{
  gchar *name;
  gint i, set;

  test_msg("=== LogMessage tests ===\n");

  LogMessage *msg = log_msg_new_empty();
  for (set = 1; set != -1; set--)
    {
      for (i = NUM_TAGS; i > -1; i--)
        {
          name = get_tag_by_id(i);

          if (set)
            log_msg_set_tag_by_name(msg, name);
          else
            log_msg_clear_tag_by_name(msg, name);
          test_msg("%s tag %d %s\n", set ? "Setting" : "Clearing", i, name);

          if (set ^ log_msg_is_tag_by_id(msg, i))
            test_fail("Tag is %sset now (by id) %d\n", set ? "not " : "", i);

          g_free(name);
        }
    }
  log_msg_unref(msg);

  msg = log_msg_new_empty();
  for (set = 1; set != -1; set--)
    {
      for (i = 0; i < NUM_TAGS; i++)
        {
          name = get_tag_by_id(i);

          if (set)
            log_msg_set_tag_by_name(msg, name);
          else
            log_msg_clear_tag_by_name(msg, name);

          test_msg("%s tag %d %s\n", set ? "Setting" : "Clearing", i, name);

          if (set ^ log_msg_is_tag_by_id(msg, i))
            test_fail("Tag is %sset now (by id) %d\n", set ? "not " : "", i);

          if (set && i < sizeof(gulong) * 8 && msg->num_tags != 0)
            test_fail("Small IDs are set which should be stored in-line but num_tags is non-zero");
          
          g_free(name);
        }
    }
  log_msg_unref(msg);

}
Esempio n. 8
0
static int remove_extent_ref(struct btrfs_root *root, u64 bytenr,
			     u64 num_bytes, u64 parent, u64 root_objectid)
{
	struct btrfs_trans_handle trans;
	struct btrfs_extent_item *item;
	struct btrfs_path *path;
	struct btrfs_key key;
	u64 refs;
	int ret;

	btrfs_init_dummy_trans(&trans);

	key.objectid = bytenr;
	key.type = BTRFS_EXTENT_ITEM_KEY;
	key.offset = num_bytes;

	path = btrfs_alloc_path();
	if (!path) {
		test_msg("Couldn't allocate path\n");
		return -ENOMEM;
	}

	path->leave_spinning = 1;
	ret = btrfs_search_slot(&trans, root, &key, path, 0, 1);
	if (ret) {
		test_msg("Couldn't find extent ref\n");
		btrfs_free_path(path);
		return ret;
	}

	item = btrfs_item_ptr(path->nodes[0], path->slots[0],
			      struct btrfs_extent_item);
	refs = btrfs_extent_refs(path->nodes[0], item);
	btrfs_set_extent_refs(path->nodes[0], item, refs - 1);
	btrfs_release_path(path);

	key.objectid = bytenr;
	if (parent) {
		key.type = BTRFS_SHARED_BLOCK_REF_KEY;
		key.offset = parent;
	} else {
		key.type = BTRFS_TREE_BLOCK_REF_KEY;
		key.offset = root_objectid;
	}

	ret = btrfs_search_slot(&trans, root, &key, path, -1, 1);
	if (ret) {
		test_msg("Couldn't find backref %d\n", ret);
		btrfs_free_path(path);
		return ret;
	}
	btrfs_del_item(&trans, root, path);
	btrfs_free_path(path);
	return ret;
}
Esempio n. 9
0
int main(int argc, char *argv[])
{
	char cmdline_orig[4096];
	char cmdline[4096];
	char env_orig[4096];
	char env[4096];
	char auxv_orig[1024];
	char auxv[1024];

	memset(cmdline_orig,	0, sizeof(cmdline_orig));
	memset(cmdline,		0, sizeof(cmdline));
	memset(env_orig,	0, sizeof(env_orig));
	memset(env,		0, sizeof(env));
	memset(auxv_orig,	0, sizeof(auxv_orig));
	memset(auxv,		0, sizeof(auxv));

	test_init(argc, argv);

	read_from_proc("/proc/self/cmdline", cmdline_orig, sizeof(cmdline_orig));
	read_from_proc("/proc/self/environ", env_orig, sizeof(env_orig));
	read_from_proc("/proc/self/auxv", auxv_orig, sizeof(auxv_orig));

	test_msg("old cmdline: %s\n", cmdline_orig);
	test_msg("old environ: %s\n", env_orig);

	test_daemon();
	test_waitsig();

	read_from_proc("/proc/self/cmdline", cmdline, sizeof(cmdline));
	read_from_proc("/proc/self/environ", env, sizeof(env));
	read_from_proc("/proc/self/auxv", auxv, sizeof(auxv));

	test_msg("new cmdline: %s\n", cmdline);
	test_msg("new environ: %s\n", env);

	if (strncmp(cmdline_orig, cmdline, sizeof(cmdline_orig))) {
		fail("cmdline corrupted on restore");
		exit(1);
	}

	if (strncmp(env_orig, env, sizeof(env_orig))) {
		fail("envirion corrupted on restore");
		exit(1);
	}

	if (memcmp(auxv_orig, auxv, sizeof(auxv_orig))) {
		fail("auxv corrupted on restore");
		exit(1);
	}

	pass();

	return 0;
}
Esempio n. 10
0
void dump_events(char *buf, int len) {
	int marker = 0;
	struct inotify_event *event;
	while (marker < len) {
		event = (struct inotify_event *) &buf[marker];
		test_msg("\t%s (%x mask, %d len", handle_event(event->mask), event->mask, event->len);
		if (event->len)
			test_msg(", '%s' name", event->name);
		test_msg(")\n");
		marker += EVENT_SIZE + event->len;
	}
}
Esempio n. 11
0
static int insert_normal_tree_ref(struct btrfs_root *root, u64 bytenr,
				  u64 num_bytes, u64 parent, u64 root_objectid)
{
	struct btrfs_trans_handle trans;
	struct btrfs_extent_item *item;
	struct btrfs_extent_inline_ref *iref;
	struct btrfs_tree_block_info *block_info;
	struct btrfs_path *path;
	struct extent_buffer *leaf;
	struct btrfs_key ins;
	u32 size = sizeof(*item) + sizeof(*iref) + sizeof(*block_info);
	int ret;

	btrfs_init_dummy_trans(&trans);

	ins.objectid = bytenr;
	ins.type = BTRFS_EXTENT_ITEM_KEY;
	ins.offset = num_bytes;

	path = btrfs_alloc_path();
	if (!path) {
		test_msg("Couldn't allocate path\n");
		return -ENOMEM;
	}

	path->leave_spinning = 1;
	ret = btrfs_insert_empty_item(&trans, root, path, &ins, size);
	if (ret) {
		test_msg("Couldn't insert ref %d\n", ret);
		btrfs_free_path(path);
		return ret;
	}

	leaf = path->nodes[0];
	item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item);
	btrfs_set_extent_refs(leaf, item, 1);
	btrfs_set_extent_generation(leaf, item, 1);
	btrfs_set_extent_flags(leaf, item, BTRFS_EXTENT_FLAG_TREE_BLOCK);
	block_info = (struct btrfs_tree_block_info *)(item + 1);
	btrfs_set_tree_block_level(leaf, block_info, 1);
	iref = (struct btrfs_extent_inline_ref *)(block_info + 1);
	if (parent > 0) {
		btrfs_set_extent_inline_ref_type(leaf, iref,
						 BTRFS_SHARED_BLOCK_REF_KEY);
		btrfs_set_extent_inline_ref_offset(leaf, iref, parent);
	} else {
		btrfs_set_extent_inline_ref_type(leaf, iref, BTRFS_TREE_BLOCK_REF_KEY);
		btrfs_set_extent_inline_ref_offset(leaf, iref, root_objectid);
	}
	btrfs_free_path(path);
	return 0;
}
Esempio n. 12
0
int btrfs_test_inodes(void)
{
	int ret;

	set_bit(EXTENT_FLAG_COMPRESSED, &compressed_only);
	set_bit(EXTENT_FLAG_VACANCY, &vacancy_only);
	set_bit(EXTENT_FLAG_PREALLOC, &prealloc_only);

	test_msg("Running btrfs_get_extent tests\n");
	ret = test_btrfs_get_extent();
	if (ret)
		return ret;
	test_msg("Running hole first btrfs_get_extent test\n");
	return test_hole_first();
}
Esempio n. 13
0
static int check_file_locks(int alt_pid, int fd)
{
	FILE		*fp_locks = NULL;
	char		buf[100], fl_flag[16], fl_type[16], fl_option[16];
	pid_t		pid = getpid();
	int		found = 0, num, fl_owner;

	fp_locks = fopen("/proc/locks", "r");
	if (!fp_locks)
		return -1;

	test_msg("C: %d/%d\n", pid, alt_pid);

	while (fgets(buf, sizeof(buf), fp_locks)) {
		test_msg("c: %s", buf);

		if (strstr(buf, "->"))
			continue;

		num = sscanf(buf,
			"%*d:%s %s %s %d %*02x:%*02x:%*d %*d %*s",
			fl_flag, fl_type, fl_option, &fl_owner);

		if (num < 4) {
			err("Invalid lock info.\n");
			break;
		}

		if (fl_owner != pid && fl_owner != alt_pid)
			continue;

		if (!strcmp(fl_flag, "FLOCK") &&
				!strcmp(fl_type, "ADVISORY") &&
				!strcmp(fl_option, "WRITE"))
			found++;

		memset(fl_flag, 0, sizeof(fl_flag));
		memset(fl_type, 0, sizeof(fl_type));
		memset(fl_option, 0, sizeof(fl_option));
	}

	fclose(fp_locks);

	if (flock(fd, LOCK_EX | LOCK_NB) == 0)
		return 0;

	return found == 1;
}
Esempio n. 14
0
int main(int argc, char **argv)
{
	char *val;
	int max_nr = 1024, i;

	val = getenv("ZDTM_THREAD_BOMB");
	if (val)
		max_nr = atoi(val);

	test_msg("%d\n", max_nr);

	test_init(argc, argv);

	for (i = 0; i < max_nr; i++) {
		pthread_t p;
		pthread_create(&p, NULL, thread_fn, NULL);
	}

	test_daemon();
	test_waitsig();

	pass();

	return 0;
}
Esempio n. 15
0
int main (int argc, char *argv[])
{
    flux_t h;
    flux_reactor_t *reactor;

    plan (4+11+3+4+3+5+2);

    (void)setenv ("FLUX_CONNECTOR_PATH", CONNECTOR_PATH, 0);
    ok ((h = flux_open ("loop://", 0)) != NULL,
        "opened loop connector");
    if (!h)
        BAIL_OUT ("can't continue without loop handle");
    flux_fatal_set (h, fatal_err, NULL);
    ok ((reactor = flux_get_reactor (h)) != NULL,
        "obtained reactor");
    if (!reactor)
        BAIL_OUT ("can't continue without reactor");

    ok (flux_reactor_run (reactor, 0) == 0,
        "general: reactor ran to completion (no watchers)");
    errno = 0;
    ok (flux_sleep_on (h, FLUX_MATCH_ANY) < 0 && errno == EINVAL,
        "general: flux_sleep_on outside coproc fails with EINVAL");

    test_timer (reactor); // 11
    test_fd (reactor); // 3
    test_zmq (reactor); // 4
    test_msg (h); // 3
    test_multmatch (h); // 5

    /* Misc
     */
    lives_ok ({ reactor_destroy_early ();},
        "destroying reactor then watcher doesn't segfault");
Esempio n. 16
0
static int fork_children(struct testcase *t, int leader)
{
	int i;
	pid_t cid;

	for (i = 0; i < TESTS; i++) {
		if (t->pid != testcases[i].ppid)
			continue;

		if (leader ^ (t->pid == testcases[i].born_sid))
				continue;

		cid = test_fork_id(i);
		if (cid < 0)
			goto err;
		if (cid == 0) {
			test_msg("I'm %d with pid %d\n", i, getpid());
			child(i);
			exit(0);
		}

		testcases[i].master.pid = cid;
	}
	return 0;
err:
	return -1;
}
Esempio n. 17
0
static int kcmp(int type, pid_t pid1, pid_t pid2, unsigned long idx1, unsigned long idx2)
{
	int ret;

	ret = syscall(SYS_kcmp, pid1, pid2, type, idx1, idx2);

	switch (ret) {
		case 0:
			break;
		case 1:
		case 2:
			test_msg("FS for pids %d and %d doesn't match: %d\n", pid1, pid2, ret);
			break;
		case -1:
			pr_err("kcmp (type: %d, pid1: %d, pid2: %d, "
					"idx1: %ld, idx2: %ld) failed: %d\n",
					type, pid1, pid2, idx1, idx2, errno);
			break;
		default:
			pr_err("kcmp (type: %d, pid1: %d, pid2: %d, "
					"idx1: %ld, idx2: %ld) returned %d\n",
					type, pid1, pid2, idx1, idx2, ret);
			break;
	}
	return ret;
}
Esempio n. 18
0
int main(int argc, char **argv)
{
	void *mem;
	int i, fail = 0;
	unsigned rover = 1;
	unsigned backup[MEM_PAGES] = {};

	srand(time(NULL));

	test_init(argc, argv);

	mem = mmap(NULL, MEM_PAGES * PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, 0, 0);
	if (mem == MAP_FAILED)
		return 1;

	test_msg("mem %p backup %p\n", mem, backup);

	test_daemon();
	while (test_go()) {
		unsigned pfn;
		struct timespec req = { .tv_sec = 0, .tv_nsec = 100000, };

		pfn = random() % MEM_PAGES;
		*(unsigned *)(mem + pfn * PAGE_SIZE) = rover;
		backup[pfn] = rover;
		test_msg("t %u %u\n", pfn, rover);
		rover++;
		nanosleep(&req, NULL);
	}
	test_waitsig();

	test_msg("final rover %u\n", rover);
	for (i = 0; i < MEM_PAGES; i++)
		if (backup[i] != *(unsigned *)(mem + i * PAGE_SIZE)) {
			test_msg("Page %u differs want %u has %u\n", i,
					backup[i], *(unsigned *)(mem + i * PAGE_SIZE));
			fail = 1;
		} else
			test_msg("Page %u matches %u\n", i, backup[i]);

	if (fail)
		fail("Memory corruption\n");
	else
		pass();

	return 0;
}
static int test_merge_none(struct btrfs_trans_handle *trans,
			   struct btrfs_fs_info *fs_info,
			   struct btrfs_block_group_cache *cache,
			   struct btrfs_path *path)
{
	struct free_space_extent extents[] = {
		{cache->key.objectid, BITMAP_RANGE},
		{cache->key.objectid + 2 * BITMAP_RANGE, BITMAP_RANGE},
		{cache->key.objectid + 4 * BITMAP_RANGE, BITMAP_RANGE},
	};
	int ret;

	ret = __remove_from_free_space_tree(trans, fs_info, cache, path,
					    cache->key.objectid,
					    cache->key.offset);
	if (ret) {
		test_msg("Could not remove free space\n");
		return ret;
	}

	ret = __add_to_free_space_tree(trans, fs_info, cache, path,
				       cache->key.objectid, BITMAP_RANGE);
	if (ret) {
		test_msg("Could not add free space\n");
		return ret;
	}

	ret = __add_to_free_space_tree(trans, fs_info, cache, path,
				       cache->key.objectid + 4 * BITMAP_RANGE,
				       BITMAP_RANGE);
	if (ret) {
		test_msg("Could not add free space\n");
		return ret;
	}

	ret = __add_to_free_space_tree(trans, fs_info, cache, path,
				       cache->key.objectid + 2 * BITMAP_RANGE,
				       BITMAP_RANGE);
	if (ret) {
		test_msg("Could not add free space\n");
		return ret;
	}

	return check_free_space_extents(trans, fs_info, cache, path,
					extents, ARRAY_SIZE(extents));
}
Esempio n. 20
0
/* Used by test_steal_space_from_bitmap_to_extent(). */
static int
check_num_extents_and_bitmaps(const struct btrfs_block_group_cache *cache,
			      const int num_extents,
			      const int num_bitmaps)
{
	if (cache->free_space_ctl->free_extents != num_extents) {
		test_msg("Incorrect # of extent entries in the cache: %d, expected %d\n",
			 cache->free_space_ctl->free_extents, num_extents);
		return -EINVAL;
	}
	if (cache->free_space_ctl->total_bitmaps != num_bitmaps) {
		test_msg("Incorrect # of extent entries in the cache: %d, expected %d\n",
			 cache->free_space_ctl->total_bitmaps, num_bitmaps);
		return -EINVAL;
	}
	return 0;
}
Esempio n. 21
0
void
test_pattern(const gchar *pattern, const gchar *rule, gboolean match)
{
  gboolean result;
  LogMessage *msg = log_msg_new_empty();
  static LogTemplate *templ;

  GString *res = g_string_sized_new(128);
  static TimeZoneInfo *tzinfo = NULL;

  PDBInput input;

  if (!tzinfo)
    tzinfo = time_zone_info_new(NULL);
  if (!templ)
    {
      templ = log_template_new(configuration, "dummy");
      log_template_compile(templ, "$TEST", NULL);
    }

  log_msg_set_value(msg, LM_V_HOST, MYHOST, strlen(MYHOST));
  log_msg_set_value(msg, LM_V_PROGRAM, "test", strlen(MYHOST));
  log_msg_set_value(msg, LM_V_MESSAGE, pattern, strlen(pattern));

  result = pattern_db_process(patterndb, PDB_INPUT_WRAP_MESSAGE(&input, msg));

  log_template_format(templ, msg, NULL, LTZ_LOCAL, 0, NULL, res);

  if (strcmp(res->str, pattern) == 0)
    {
       test_msg("Rule: '%s' Value '%s' is inserted into $TEST res:(%s)\n", rule, pattern, res->str);
    }

  if ((match && !result) || (!match && result))
     {
       test_fail("FAIL: Value '%s' is %smatching for pattern '%s' \n", rule, !!result ? "" : "not ", pattern);
     }
   else
    {
       test_msg("Value '%s' is %smatching for pattern '%s' \n", rule, !!result ? "" : "not ", pattern);
     }

  g_string_free(res, TRUE);

  log_msg_unref(msg);
}
Esempio n. 22
0
int main(int argc, char **argv)
{
	pid_t pid;

	test_init(argc, argv);

	pid = fork();
	if (pid < 0) {
		fail("fork() failed");
		return -1;
	}

	if (pid == 0) {
		test_msg("child is %d\n", pid);
		/* Child process just sleeps until it is killed. All we need
		 * here is a process to open the mountinfo of. */
		while(1)
			sleep(10);
	} else {
		int fd, ret;
		char path[PATH_MAX];
		pid_t result;

		sprintf(path, "/proc/%d/mountinfo", pid);
		fd = open(path, O_RDONLY);
		if (fd < 0) {
			fail("failed to open fd");
			return -1;
		}

		/* no matter what, we should kill the child */
		kill(pid, SIGKILL);
		result = waitpid(pid, NULL, 0);
		if (result < 0) {
			fail("failed waitpid()");
			return -1;
		}

		if (fd < 0) {
			fail("failed opening %s", path);
			return -1;
		}

		test_daemon();
		test_waitsig();

		ret = fcntl(fd, F_GETFD);
		close(fd);

		if (ret) {
			fail("bad fd after restore");
			return -1;
		}
	}

	pass();
	return 0;
}
Esempio n. 23
0
void
test_tags(void)
{
  guint i, check;
  guint id;
  gchar *name;
  const gchar *tag_name;

  for (check = 0; check < 2; check++)
    for (i = 0; i < NUM_TAGS; i++)
      {
        name = get_tag_by_id(i);
        id = log_tags_get_by_name(name);
        test_msg("%s tag %s %d\n", check ? "Checking" : "Adding", name, id);
        if (id != i)
          test_fail("Invalid tag id %d %s\n", id, name);

        g_free(name);
      }

  for (i = 0; i < NUM_TAGS; i++)
    {
      name = get_tag_by_id(i);

      tag_name = log_tags_get_by_id(i);
      test_msg("Looking up tag by id %d %s(%s)\n", i, tag_name, name);
      if (tag_name)
        {
          if (!g_str_equal(tag_name, name))
            test_fail("Bad tag name for id %d %s (%s)\n", i, tag_name, name);
        }
      else
        test_fail("Error looking up tag by id %d %s\n", i, name);

      g_free(name);
    }

  for (i = NUM_TAGS; i < (NUM_TAGS + 3); i++)
    {
      tag_name = log_tags_get_by_id(i);
      test_msg("Looking up tag by invalid id %d\n", i);
      if (tag_name)
        test_fail("Found tag name for invalid id %d %s\n", i, tag_name);
    }
}
Esempio n. 24
0
int btrfs_test_inodes(u32 sectorsize, u32 nodesize)
{
	int ret;

	set_bit(EXTENT_FLAG_COMPRESSED, &compressed_only);
	set_bit(EXTENT_FLAG_PREALLOC, &prealloc_only);

	test_msg("Running btrfs_get_extent tests\n");
	ret = test_btrfs_get_extent(sectorsize, nodesize);
	if (ret)
		return ret;
	test_msg("Running hole first btrfs_get_extent test\n");
	ret = test_hole_first(sectorsize, nodesize);
	if (ret)
		return ret;
	test_msg("Running outstanding_extents tests\n");
	return test_extent_accounting(sectorsize, nodesize);
}
Esempio n. 25
0
static void sig_handler(int signal, siginfo_t *info, void *data)
{
	uint32_t crc;

	test_msg("signo=%d si_code=%x\n", signal, info->si_code);

	if (test_go()) {
		pr_perror("The signal is received before unlocking");
		return;
	}

	switch (signal) {
	case SIGCHLD:
		if ((info->si_code & CLD_EXITED) &&
		    (info->si_pid == child) &&
		    (info->si_status == 5))
			numsig++;
		else {
			fail("Wrong siginfo");
			exit(1);
		}
		return;
	}

	if (TESTSIG == signal || THREADSIG == signal) {
		siginfo_t *src;

		if (signal == TESTSIG) {
			src = &share_infos[share_nr];
			share_nr++;
		} else if (getpid() == syscall(SYS_gettid)) {
			src = &self_infos[self_nr];
			self_nr++;
		} else {
			src = &thread_infos[thread_nr];
			thread_nr++;
		}

		crc = ~0;
		if (datachk((uint8_t *) &info->_sifields,
			    sizeof(siginfo_t) - offsetof(siginfo_t, _sifields), &crc)) {
			fail("CRC mismatch\n");
			return;
		}

		 if (memcmp(info, src, sizeof(siginfo_t))) {
			fail("Source and received info are differ\n");
			return;
		}

		numsig++;
		return;
	}

	pr_perror("Unexpected signal");
	exit(1);
}
Esempio n. 26
0
int btrfs_test_free_space_cache(void)
{
	struct btrfs_block_group_cache *cache;
	struct btrfs_root *root = NULL;
	int ret = -ENOMEM;

	test_msg("Running btrfs free space cache tests\n");

	cache = init_test_block_group();
	if (!cache) {
		test_msg("Couldn't run the tests\n");
		return 0;
	}

	root = btrfs_alloc_dummy_root();
	if (!root)
		goto out;

	root->fs_info = btrfs_alloc_dummy_fs_info();
	if (!root->fs_info)
		goto out;

	root->fs_info->extent_root = root;
	cache->fs_info = root->fs_info;

	ret = test_extents(cache);
	if (ret)
		goto out;
	ret = test_bitmaps(cache);
	if (ret)
		goto out;
	ret = test_bitmaps_and_extents(cache);
	if (ret)
		goto out;

	ret = test_steal_space_from_bitmap_to_extent(cache);
out:
	__btrfs_remove_free_space_cache(cache->free_space_ctl);
	kfree(cache->free_space_ctl);
	kfree(cache);
	btrfs_free_dummy_root(root);
	test_msg("Free space cache tests finished\n");
	return ret;
}
Esempio n. 27
0
static int clone_func(void *_arg)
{
	struct clone_args *args = (struct clone_args *) _arg;

	current = args->id;

	test_msg("%3d: Hello. My pid is %d\n", args->id, getpid());
	mainloop();
	exit(0);
}
Esempio n. 28
0
void sig_handler(int signo, siginfo_t *siginfo, void *data)
{
	int pid, ret;
	test_msg("receive signal sig=%d from pid=%d\n", signo, siginfo->si_pid);
	pid = siginfo->si_pid;
	ret = write(child_fd, &pid, sizeof(pid));
	if (ret != sizeof(pid))
		err("write");
	child_exit = 1;
}
Esempio n. 29
0
int read_reply()
{
	//string to hold content of the route
	// table (i.e. one entry)
	char dsts[24], gws[24], ifs[16], ms[24];
	// outer loop: loops thru all the NETLINK
	// headers that also include the route entry
	// header
	nlp = (struct nlmsghdr *) buf;
	for(; NLMSG_OK(nlp, nll); nlp = NLMSG_NEXT(nlp, nll))
	{
		// get route entry header
		rtp = (struct rtmsg *) NLMSG_DATA(nlp);
		// we are only concerned about the
		// main route table
		if(rtp->rtm_table != RT_TABLE_MAIN)
			continue;
		// init all the strings
		bzero(dsts, sizeof(dsts));
		bzero(gws, sizeof(gws));
		bzero(ifs, sizeof(ifs));
		bzero(ms, sizeof(ms));
		// inner loop: loop thru all the attributes of
		// one route entry
		rtap = (struct rtattr *) RTM_RTA(rtp);
		rtl = RTM_PAYLOAD(nlp);
		for( ; RTA_OK(rtap, rtl); rtap = RTA_NEXT(rtap,rtl))
		{
			switch(rtap->rta_type)
			{
				// destination IPv4 address
				case RTA_DST:
					inet_ntop(AF_INET, RTA_DATA(rtap),
							dsts, 24);
					break;
					// next hop IPv4 address
				case RTA_GATEWAY:
					inet_ntop(AF_INET, RTA_DATA(rtap),
							gws, 24);
					break;
					// unique ID associated with the network
					// interface
				case RTA_OIF:
					sprintf(ifs, "%d",
							*((int *) RTA_DATA(rtap)));
				default:
					break;
			}
		}
		sprintf(ms, "%d", rtp->rtm_dst_len);
		test_msg("dst %s/%s gw %s if %s\n",
				dsts, ms, gws, ifs);
	}
	return 0;
}
Esempio n. 30
0
int tcp_init_server(int family, int *port)
{
	union sockaddr_inet addr;
	int sock;
	int yes = 1, ret;

	memset(&addr,0,sizeof(addr));
	if (family == AF_INET) {
		addr.v4.sin_family = family;
		inet_pton(family, "0.0.0.0", &(addr.v4.sin_addr));
	} else if (family == AF_INET6){
		addr.v6.sin6_family = family;
		inet_pton(family, "::0", &(addr.v6.sin6_addr));
	} else
		return -1;

	sock = socket(family, SOCK_STREAM, IPPROTO_TCP);
	if (sock == -1) {
		err ("socket() failed %m");
		return -1;
	}

	if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1 ) {
		err("setsockopt() error");
		return -1;
	}

	while (1) {
		if (family == AF_INET)
			addr.v4.sin_port = htons(*port);
		else if (family == AF_INET6)
			addr.v6.sin6_port = htons(*port);

		ret = bind(sock, (struct sockaddr *) &addr, sizeof(addr));

		/* crtools doesn't restore sock opts, so we need this hack */
		if (ret == -1 && errno == EADDRINUSE) {
			test_msg("The port %d is already in use.\n", *port);
			(*port)++;
			continue;
		}
		break;
	}

	if (ret == -1) {
		err ("bind() failed %m");
		return -1;
	}

	if (listen(sock, 1) == -1) {
		err ("listen() failed %m");
		return -1;
	}
	return sock;
}