当前位置: 首页>>代码示例>>C++>>正文


C++ SAFE_FILE_PRINTF函数代码示例

本文整理汇总了C++中SAFE_FILE_PRINTF函数的典型用法代码示例。如果您正苦于以下问题:C++ SAFE_FILE_PRINTF函数的具体用法?C++ SAFE_FILE_PRINTF怎么用?C++ SAFE_FILE_PRINTF使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SAFE_FILE_PRINTF函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: testoom

void testoom(int mempolicy, int lite, int retcode, int allow_sigkill)
{
	int ksm_run_orig;

	set_global_mempolicy(mempolicy);

	tst_res(TINFO, "start normal OOM testing.");
	oom(NORMAL, lite, retcode, allow_sigkill);

	tst_res(TINFO, "start OOM testing for mlocked pages.");
	oom(MLOCK, lite, retcode, allow_sigkill);

	/*
	 * Skip oom(KSM) if lite == 1, since limit_in_bytes may vary from
	 * run to run, which isn't reliable for oom03 cgroup test.
	 */
	if (access(PATH_KSM, F_OK) == -1 || lite == 1) {
		tst_res(TINFO, "KSM is not configed or lite == 1, "
			 "skip OOM test for KSM pags");
	} else {
		tst_res(TINFO, "start OOM testing for KSM pages.");
		SAFE_FILE_SCANF(PATH_KSM "run", "%d", &ksm_run_orig);
		SAFE_FILE_PRINTF(PATH_KSM "run", "1");
		oom(KSM, lite, retcode, allow_sigkill);
		SAFE_FILE_PRINTF(PATH_KSM "run", "%d", ksm_run_orig);
	}
}
开发者ID:sathnaga,项目名称:ltp,代码行数:27,代码来源:mem.c

示例2: cleanup

static void cleanup(void)
{
	if (opt_shmid && shmid != -1)
		SAFE_SHMCTL(shmid, IPC_RMID, NULL);

	if (!opt_shmid && fd != -1) {
		SAFE_CLOSE(fd);
		SAFE_UNLINK(TEST_FILE);
	}

	if (mounted)
		tst_umount(MOUNT_DIR);

	if (restore_nr_hgpgs) {
		tst_res(TINFO, "restore nr_hugepages to %ld.", nr_hugepages);
		SAFE_FILE_PRINTF(path, "%ld", nr_hugepages);
	}

	if (restore_shmmax)
		SAFE_FILE_PRINTF(PATH_SHMMAX, "%llu", shmmax);

	if (restore_overcomm_hgpgs) {
		tst_res(TINFO, "restore nr_overcommit_hugepages to %ld.",
			nr_overcommit_hugepages);
		SAFE_FILE_PRINTF(pathover, "%ld", nr_overcommit_hugepages);
	}
}
开发者ID:kraj,项目名称:ltp,代码行数:27,代码来源:hugemmap05.c

示例3: setup

static void setup(void)
{
	int fd;
	tst_require_root(NULL);

	fd = open(boost, O_RDWR);
	if (fd == -1) {
		tst_brkm(TCONF, NULL,
			"acpi-cpufreq not loaded or overclock not supported");
	}
	close(fd);

	tst_sig(FORK, DEF_HANDLER, cleanup);

	SAFE_FILE_SCANF(NULL, boost, "%d", &boost_value);

	SAFE_FILE_SCANF(NULL, up_limit, "%d", &threshold);

	/* change cpu0 scaling governor */
	SAFE_FILE_SCANF(NULL, governor, "%s", governor_name);
	SAFE_FILE_PRINTF(cleanup, governor, "%s", "userspace");

	/* use only cpu0 */
	cpu_set_t set;
	CPU_ZERO(&set);
	CPU_SET(0, &set);
	if (sched_setaffinity(0, sizeof(cpu_set_t), &set) < 0)
		tst_brkm(TBROK | TERRNO, cleanup, "failed to set CPU0");

	SAFE_FILE_PRINTF(cleanup, up_limit, "11");
}
开发者ID:MohdVara,项目名称:ltp,代码行数:31,代码来源:ltp_acpi_cpufreq.c

示例4: setup

void setup(void)
{
	tst_require_root(NULL);

	if (access(PATH_THP, F_OK) == -1)
		tst_brkm(TCONF, NULL, "THP is not enabled");

	SAFE_FILE_SCANF(NULL, PATH_KHPD "scan_sleep_millisecs",
			"%d", &pre_thp_scan_sleep_millisecs);
	/* set 0 to khugepaged/scan_sleep_millisecs to run khugepaged 100% */
	SAFE_FILE_PRINTF(NULL, PATH_KHPD "scan_sleep_millisecs", "0");

	SAFE_FILE_SCANF(NULL, PATH_KHPD "alloc_sleep_millisecs",
			"%d", &pre_thp_alloc_sleep_millisecs);
	/*
	 * set 0 to khugepaged/alloc_sleep_millisecs to make sure khugepaged
	 * don't stop if there's a hugepage allcation failure.
	 */
	SAFE_FILE_PRINTF(NULL, PATH_KHPD "alloc_sleep_millisecs", "0");

	SAFE_FILE_SCANF(NULL, PATH_THP "enabled", "%[^\n]", pre_thp_enabled);
	/* open khugepaged as 'always' mode */
	SAFE_FILE_PRINTF(NULL, PATH_THP "enabled", "always");

	tst_sig(FORK, DEF_HANDLER, NULL);
	TEST_PAUSE;
}
开发者ID:MohdVara,项目名称:ltp,代码行数:27,代码来源:thp04.c

示例5: do_test

static void do_test(void)
{
	int i;

	if (!SAFE_FORK()) {
		SAFE_FILE_PRINTF(PATH_AUTOGROUP, "%d", 1);
		SAFE_SETSID();

		if (SAFE_FORK())
			pause();

		SAFE_KILL(getppid(), SIGKILL);
		usleep(1000);

		// The child has gone, the grandchild runs with kref == 1
		SAFE_FILE_PRINTF(PATH_AUTOGROUP, "%d", 0);
		SAFE_SETSID();

		// runs with the freed ag/tg
		for (i = 0; i < LOOPS; i++)
			usleep(10);

		TST_CHECKPOINT_WAKE(0);

		exit(0);
	}

	SAFE_WAIT(NULL); // destroy the child's ag/tg

	TST_CHECKPOINT_WAIT(0);

	tst_res(TPASS, "Bug not reproduced");
}
开发者ID:kraj,项目名称:ltp,代码行数:33,代码来源:autogroup01.c

示例6: setup

void setup(void)
{
	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	tst_tmpdir();

	char *abs_path = tst_get_tmpdir();

	SAFE_ASPRINTF(cleanup, &testfile3, "%s/fstatattestfile3.txt", abs_path);
	free(abs_path);

	SAFE_MKDIR(cleanup, pathname, 0700);

	fds[0] = SAFE_OPEN(cleanup, pathname, O_DIRECTORY);
	fds[1] = fds[4] = fds[0];

	SAFE_FILE_PRINTF(cleanup, testfile, testfile);
	SAFE_FILE_PRINTF(cleanup, testfile2, testfile2);

	fds[2] =  SAFE_OPEN(cleanup, testfile3, O_CREAT | O_RDWR, 0600);

	fds[3] = 100;
	fds[5] = AT_FDCWD;

	filenames[0] = filenames[2] = filenames[3] = filenames[4] =
	    filenames[5] = testfile;
	filenames[1] = testfile3;

	TEST_PAUSE;
}
开发者ID:kraj,项目名称:ltp,代码行数:30,代码来源:fstatat01.c

示例7: main

int main(int argc, char *argv[])
{
    char *msg;
    int lc;
    int swap_acc_on = 1;

    msg = parse_opts(argc, argv, NULL, NULL);
    if (msg != NULL)
        tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

#if __WORDSIZE == 32
    tst_brkm(TCONF, NULL, "test is not designed for 32-bit system.");
#endif

    setup();

    for (lc = 0; TEST_LOOPING(lc); lc++) {
        tst_count = 0;

        tst_resm(TINFO, "OOM on CPUSET & MEMCG...");
        testoom(0, 0);

        /*
         * Under NUMA system, the migration of cpuset's memory
         * is in charge of cpuset.memory_migrate, we can write
         * 1 to cpuset.memory_migrate to enable the migration.
         */
        if (is_numa(cleanup)) {
            write_cpuset_files(CPATH_NEW, "memory_migrate", "1");
            tst_resm(TINFO, "OOM on CPUSET & MEMCG with "
                     "cpuset.memory_migrate=1");
            testoom(0, 0);
        }

        if (access(MEMCG_SW_LIMIT, F_OK) == -1) {
            if (errno == ENOENT) {
                tst_resm(TCONF,
                         "memcg swap accounting is disabled");
                swap_acc_on = 0;
            } else
                tst_brkm(TBROK|TERRNO, cleanup, "access");
        }

        if (swap_acc_on) {
            tst_resm(TINFO, "OOM on CPUSET & MEMCG with "
                     "special memswap limitation:");
            SAFE_FILE_PRINTF(cleanup, MEMCG_SW_LIMIT, "%ld", TESTMEM);
            testoom(0, 0);

            tst_resm(TINFO, "OOM on CPUSET & MEMCG with "
                     "disabled memswap limitation:");
            SAFE_FILE_PRINTF(cleanup, MEMCG_SW_LIMIT, "-1");
            testoom(0, 0);
        }
    }

    cleanup();
    tst_exit();
}
开发者ID:nloopa,项目名称:Linux-Test-Project,代码行数:59,代码来源:oom05.c

示例8: setup

static void setup(void)
{
	check_hugepage();
	hugepagesize = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
	init_sys_sz_paths();

	if (opt_sysfs) {
		path = path_sys_sz_huge;
		pathover = path_sys_sz_over;
	} else {
		path = PATH_PROC_HUGE;
		pathover = PATH_PROC_OVER;
	}

	if (opt_alloc) {
		size = atoi(opt_alloc);
		length = (size + size * 0.5) * 2;
	}

	if (opt_shmid) {
		SAFE_FILE_SCANF(PATH_SHMMAX, "%llu", &shmmax);
		if (shmmax < (unsigned long long)(length / 2 * hugepagesize)) {
			restore_shmmax = 1;
			SAFE_FILE_PRINTF(PATH_SHMMAX, "%ld",
					(length / 2 * hugepagesize));
		}
	}

	SAFE_FILE_SCANF(path, "%ld", &nr_hugepages);
	tst_res(TINFO, "original nr_hugepages is %ld", nr_hugepages);

	/* Reset. */
	SAFE_FILE_PRINTF(path, "%ld", size);
	restore_nr_hgpgs = 1;

	if (access(pathover, F_OK)) {
		tst_brk(TCONF, "file %s does not exist in the system",
			pathover);
	}

	SAFE_FILE_SCANF(pathover, "%ld", &nr_overcommit_hugepages);
	tst_res(TINFO, "original nr_overcommit_hugepages is %ld",
		nr_overcommit_hugepages);

	/* Reset. */
	SAFE_FILE_PRINTF(pathover, "%ld", size);
	restore_overcomm_hgpgs = 1;

	SAFE_MKDIR(MOUNT_DIR, 0700);
	SAFE_MOUNT(NULL, MOUNT_DIR, "hugetlbfs", 0, NULL);
	mounted = 1;

	if (opt_shmid) {
		/* Use /proc/meminfo to generate an IPC key. */
		key = ftok(PATH_MEMINFO, strlen(PATH_MEMINFO));
		if (key == -1)
			tst_brk(TBROK | TERRNO, "ftok");
	}
}
开发者ID:kraj,项目名称:ltp,代码行数:59,代码来源:hugemmap05.c

示例9: cleanup

static void cleanup(void)
{
	SAFE_FILE_PRINTF(NULL, boost, "%d", boost_value);

	if (governor[0] != '\0')
		SAFE_FILE_PRINTF(NULL, governor, "%s", governor_name);

	if (threshold)
		SAFE_FILE_PRINTF(NULL, up_limit, "%d", threshold);

	TEST_CLEANUP;
}
开发者ID:MohdVara,项目名称:ltp,代码行数:12,代码来源:ltp_acpi_cpufreq.c

示例10: setup

static void setup(void)
{
	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;

	tst_tmpdir();

	fd2 = SAFE_OPEN(cleanup, ".", O_DIRECTORY);

	SAFE_FILE_PRINTF(cleanup, "test_file", "A");

	fd3 = SAFE_OPEN(cleanup, "test_file", O_RDWR);

#if !defined(UCLINUX)
	outside_buf = SAFE_MMAP(cleanup, 0, 1, PROT_NONE,
				MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
#endif

	addr4 = SAFE_MEMALIGN(cleanup, getpagesize(), (4096 * 10));
	addr5 = addr4 + 1;

	fs_type = tst_fs_type(cleanup, ".");
	if (fs_type != TST_TMPFS_MAGIC)
		fd4 = SAFE_OPEN(cleanup, "test_file", O_RDWR | O_DIRECT);
}
开发者ID:Nudiv,项目名称:ltp,代码行数:26,代码来源:read02.c

示例11: setup

void setup(void)
{
	long mem_total, hpage_size;

	tst_require_root();

	mem_total = read_meminfo("MemTotal:");
	SAFE_FILE_SCANF(NULL, PATH_SHMMAX, "%ld", &orig_shmmax);
	SAFE_FILE_PRINTF(NULL, PATH_SHMMAX, "%ld", (long)SIZE);
	SAFE_FILE_SCANF(NULL, PATH_SHMMAX, "%ld", &new_shmmax);

	if (mem_total < 2L*1024*1024)
		tst_brkm(TCONF,	NULL, "Needed > 2GB RAM, have: %ld", mem_total);

	if (new_shmmax < SIZE)
		tst_brkm(TCONF,	NULL, "shmmax too low, have: %ld", new_shmmax);

	orig_hugepages = get_sys_tune("nr_hugepages");
	hpage_size = read_meminfo("Hugepagesize:") * 1024;

	hugepages = (orig_hugepages * hpage_size + SIZE) / hpage_size;
	set_sys_tune("nr_hugepages", hugepages, 1);

	TEST_PAUSE;
}
开发者ID:liaoqingwei,项目名称:ltp,代码行数:25,代码来源:hugeshmat04.c

示例12: client_run

static void client_run(void)
{
	void *res = NULL;
	long clnt_time = 0;
	int i;
	for (i = 0; i < clients_num; ++i) {
		pthread_join(thread_ids[i], &res);
		if (res) {
			tst_brkm(TBROK, cleanup, "client[%d] failed: %s",
				i, strerror((intptr_t)res));
		}
	}

	clock_gettime(CLOCK_MONOTONIC_RAW, &tv_client_end);
	clnt_time = (tv_client_end.tv_sec - tv_client_start.tv_sec) * 1000 +
		(tv_client_end.tv_nsec - tv_client_start.tv_nsec) / 1000000;

	tst_resm(TINFO, "total time '%ld' ms", clnt_time);

	/* ask server to terminate */
	client_msg[0] = start_fin_byte;
	int cfd = client_connect_send(client_msg, client_msg_size);
	if (cfd != -1) {
		shutdown(cfd, SHUT_WR);
		SAFE_CLOSE(NULL, cfd);
	}
	/* the script tcp_fastopen_run.sh will remove it */
	SAFE_FILE_PRINTF(cleanup, rpath, "%ld", clnt_time);
}
开发者ID:MohdVara,项目名称:ltp,代码行数:29,代码来源:tcp_fastopen.c

示例13: setup

void setup(void)
{
	if ((tst_kvercmp(2, 6, 17)) < 0) {
		tst_brkm(TCONF, cleanup, "This test can only run on kernels "
			"that are 2.6.17 or higher");
	}

	TEST_PAUSE;

	tst_sig(FORK, DEF_HANDLER, cleanup);

	tst_tmpdir();

	SAFE_FILE_PRINTF(cleanup, TEST_FILE, STR);
	rdfd = SAFE_OPEN(cleanup, TEST_FILE, O_RDONLY);

	wrfd = SAFE_OPEN(cleanup, TEST_FILE2,
		O_WRONLY | O_CREAT, 0644);

	appendfd = SAFE_OPEN(cleanup, TEST_FILE3,
		O_RDWR | O_CREAT | O_APPEND, 0644);

	SAFE_PIPE(cleanup, pipes);

	SAFE_WRITE(cleanup, 1, pipes[1], STR, sizeof(STR) - 1);
}
开发者ID:MohdVara,项目名称:ltp,代码行数:26,代码来源:splice03.c

示例14: setup

void setup(void)
{
	tst_require_root(NULL);

	if (tst_kvercmp(2, 6, 32) < 0)
		tst_brkm(TCONF, NULL, "2.6.32 or greater kernel required");
	if (access(PATH_KSM, F_OK) == -1)
		tst_brkm(TCONF, NULL, "KSM configuration is not enabled");

	/*
	 * kernel commit 90bd6fd introduced a new KSM sysfs knob
	 * /sys/kernel/mm/ksm/merge_across_nodes, setting it to '0'
	 * will prevent KSM pages being merged across numa nodes,
	 * which will cause the case fail, so we need to make sure
	 * it is enabled before testing.
	 */
	if (access(PATH_KSM "merge_across_nodes", F_OK) == 0) {
		SAFE_FILE_SCANF(NULL, PATH_KSM "merge_across_nodes",
				"%d", &merge_across_nodes);
		SAFE_FILE_PRINTF(NULL, PATH_KSM "merge_across_nodes", "1");
	}

	tst_sig(FORK, DEF_HANDLER, NULL);
	TEST_PAUSE;
}
开发者ID:heluxie,项目名称:LTP,代码行数:25,代码来源:ksm01.c

示例15: main

int main(int argc, char *argv[])
{
	const char *msg;
	int lc;

	msg = parse_opts(argc, argv, NULL, NULL);
	if (msg != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

#if __WORDSIZE == 32
	tst_brkm(TCONF, NULL, "test is not designed for 32-bit system.");
#endif

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		tst_count = 0;

		SAFE_FILE_PRINTF(cleanup, MEMCG_PATH_NEW "/tasks",
				 "%d", getpid());
		SAFE_FILE_PRINTF(cleanup, MEMCG_LIMIT, "%ld", TESTMEM);

		testoom(0, 0, ENOMEM, 1);

		if (access(MEMCG_SW_LIMIT, F_OK) == -1) {
			if (errno == ENOENT)
				tst_resm(TCONF,
					 "memcg swap accounting is disabled");
			else
				tst_brkm(TBROK | TERRNO, cleanup, "access");
		} else {
			SAFE_FILE_PRINTF(cleanup, MEMCG_SW_LIMIT,
					 "%ld", TESTMEM);
			testoom(0, 1, ENOMEM, 1);
		}

		/* OOM for MEMCG with mempolicy */
		if (is_numa(cleanup)) {
			tst_resm(TINFO, "OOM on MEMCG & mempolicy...");
			testoom(MPOL_BIND, 0, ENOMEM, 1);
			testoom(MPOL_INTERLEAVE, 0, ENOMEM, 1);
			testoom(MPOL_PREFERRED, 0, ENOMEM, 1);
		}
	}
	cleanup();
	tst_exit();
}
开发者ID:MohdVara,项目名称:ltp,代码行数:47,代码来源:oom03.c


注:本文中的SAFE_FILE_PRINTF函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。