<commit_before>
#include <unistd.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mount.h>
#include <limits.h>
#include "zdtmtst.h"

const char *test_doc	= "Check that some cgroups properties in kernel controllers are preserved";
const char *test_author	= "<NAME> <<EMAIL>>";

char *dirname;
TEST_OPTION(dirname, string, "cgroup directory name", 1);
static const char *cgname = "zdtmtst";

int write_value(const char *path, const char *value)
{
	int fd, l;

	fd = open(path, O_WRONLY);
	if (fd < 0) {
		pr_perror("open %s", path);
		return -1;
	}

	l = write(fd, value, strlen(value));
	close(fd);
	if (l < 0) {
		pr_perror("failed to write %s to %s", value, path);
		return -1;
	}

	return 0;
}

int mount_and_add(const char *controller, const char *path, const char *prop, const char *value)
{
	char aux[1024], paux[1024], subdir[1024];

	if (mkdir(dirname, 0700) < 0 && errno != EEXIST) {
		pr_perror("Can't make dir");
		return -1;
	}

	sprintf(subdir, "%s/%s", dirname, controller);
	if (mkdir(subdir, 0700) < 0) {
		pr_perror("Can't make dir");
		return -1;
	}

	if (mount("none", subdir, "cgroup", 0, controller)) {
		pr_perror("Can't mount cgroups");
		goto err_rd;
	}

	sprintf(paux, "%s/%s", subdir, path);
	mkdir(paux, 0600);

	sprintf(paux, "%s/%s/%s", subdir, path, prop);
	if (write_value(paux, value) < 0)
		goto err_rs;

	sprintf(aux, "%d", getpid());
	sprintf(paux, "%s/%s/tasks", subdir, path);
	/*
	if (write_value(paux, aux) < 0)
		goto err_rs;
	*/

	return 0;
err_rs:
	umount(dirname);
err_rd:
	rmdir(dirname);
	return -1;
}

bool checkval(char *path, char *val)
{
	FILE *f;
	char buf[64];

	f = fopen(path, "r");
	if (!f) {
		pr_perror("fopen %s", path);
		return false;
	}

	fgets(buf, sizeof(buf), f);
	fclose(f);

	if (strcmp(val, buf)) {
		pr_err("got %s expected %s\n", buf, val);
		return false;<commit_msg>tests: remove commented out code<commit_after>
#include <unistd.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mount.h>
#include <limits.h>
#include "zdtmtst.h"

const char *test_doc	= "Check that some cgroups properties in kernel controllers are preserved";
const char *test_author	= "<NAME> <<EMAIL>>";

char *dirname;
TEST_OPTION(dirname, string, "cgroup directory name", 1);
static const char *cgname = "zdtmtst";

int write_value(const char *path, const char *value)
{
	int fd, l;

	fd = open(path, O_WRONLY);
	if (fd < 0) {
		pr_perror("open %s", path);
		return -1;
	}

	l = write(fd, value, strlen(value));
	close(fd);
	if (l < 0) {
		pr_perror("failed to write %s to %s", value, path);
		return -1;
	}

	return 0;
}

int mount_and_add(const char *controller, const char *path, const char *prop, const char *value)
{
	char aux[1024], paux[1024], subdir[1024];

	if (mkdir(dirname, 0700) < 0 && errno != EEXIST) {
		pr_perror("Can't make dir");
		return -1;
	}

	sprintf(subdir, "%s/%s", dirname, controller);
	if (mkdir(subdir, 0700) < 0) {
		pr_perror("Can't make dir");
		return -1;
	}

	if (mount("none", subdir, "cgroup", 0, controller)) {
		pr_perror("Can't mount cgroups");
		goto err_rd;
	}

	sprintf(paux, "%s/%s", subdir, path);
	mkdir(paux, 0600);

	sprintf(paux, "%s/%s/%s", subdir, path, prop);
	if (write_value(paux, value) < 0)
		goto err_rs;

	sprintf(aux, "%d", getpid());
	sprintf(paux, "%s/%s/tasks", subdir, path);
	if (write_value(paux, aux) < 0)
		goto err_rs;

	return 0;
err_rs:
	umount(dirname);
err_rd:
	rmdir(dirname);
	return -1;
}

bool checkval(char *path, char *val)
{
	FILE *f;
	char buf[64];

	f = fopen(path, "r");
	if (!f) {
		pr_perror("fopen %s", path);
		return false;
	}

	fgets(buf, sizeof(buf), f);
	fclose(f);

	if (strcmp(val, buf)) {
		pr_err("got %s expected %s\n", buf, val);
		return false;
{'fraction_non_alphanumeric': 0.18476289194091733, 'fraction_numerical': 0.021249028245659496, 'mean_word_length': 4.30949105914718, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6511220', 'n_tokens_mistral': 1722, 'n_tokens_neox': 1598, 'n_words': 437}