<commit_before>#!/bin/bash
# usage ./runlibcgrouptest.sh
# Copyright IBM Corporation. 2008
#
# Author:	<NAME> <<EMAIL>>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2.1 of the GNU Lesser General Public License
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it would be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# Description: This script runs the the basic tests for testing libcgroup apis.
#

DEBUG=false;		# for debug messages
FS_MOUNTED=0;		# 0 for not mounted, 1 for mounted, 2 for multimounted
MOUNTPOINT=/dev/cgroup_controllers;	# Just to initialize
TARGET=/dev/cgroup_controllers;
CONTROLLERS=cpu,memory;
NUM_MOUNT=1;		# Number of places to be mounted on

debug()
{
	# Function parameter is the string to print out
	if $DEBUG
	then
		echo SH:DBG: $1;
	fi
}

check_mount_fs ()
{
	local NUM_MOUNT=0;
	CGROUP=`cat /proc/mounts|grep -w cgroup|tr -s [:space:]|cut -d" " -f3`;

	# get first word in case of multiple mounts
	CGROUP=`echo $CGROUP|cut -d" " -f1`;

	debug "check_mount_fs(): CGROUP is $CGROUP";
	if [ "$CGROUP" = "cgroup" ]
	then
		NUM_MOUNT=`cat /proc/mounts|grep -w cgroup|wc -l`;
		debug "check_mount_fs(): fs mounted at $NUM_MOUNT places";

		if [ $NUM_MOUNT -eq 1 ]
		then
			FS_MOUNTED=1;
		else
			# Any number of mounts is multi mount
			FS_MOUNTED=2;
		fi;
		return 0;	# True
	else
		FS_MOUNTED=0;
		return 1;	# false
	fi
}

umount_fs ()
{
	while check_mount_fs
	do
		PROC_ENTRY=`cat /proc/mounts|grep cgroup|tr -s [:space:]|cut -d" " -f2`;
		# Get first mountpoint in case of multiple mounts
		PROC_ENTRY=`echo $PROC_ENTRY|cut -d" " -f1`;
		if [ -n "$PROC_ENTRY" ]
		then
			TARGET=$PROC_ENTRY;
			# Need to take care if there are tasks running in any group ??
			# Also need to care if cpu and memory are mounted at different places
			rmdir $TARGET/* 2> /dev/null ;
			umount $TARGET;
			rmdir  $TARGET;
			debug "umounted $TARGET";
		fi;
	done
	FS_MOUNTED=0;
	TARGET=/dev/cgroup_controllers;	#??
	echo "Cleanup done";
}

# Check if kernel is not having any of the controllers enabled
no_controllers()
{
	CPU="";
	MEMORY="";
	if [ -e /proc/cgroups ]
	then
		CPU=`cat /proc/cgroups|grep -w cpu|cut -f1`;
		MEMORY=`cat /proc/cgroups|grep -w memory|cut -f1`;
	fi;

	if [ -n $CPU ] && [ -n $MEMORY ]
	then
		CONTROLLERS=$CPU,$MEMORY ;
		return 1;	# false
	elif [ -n $CPU ]
	then
		CONTROLLERS=$CPU ;
		return 1;	# false
	elif [ -n $MEMORY ]
	then
		CONTROLLERS=$MEMORY ;<commit_msg>libcgroup Test: change subsyscheck logic in testscript<commit_after>#!/bin/bash
# usage ./runlibcgrouptest.sh
# Copyright IBM Corporation. 2008
#
# Author:	<NAME> <<EMAIL>>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2.1 of the GNU Lesser General Public License
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it would be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# Description: This script runs the the basic tests for testing libcgroup apis.
#

DEBUG=false;		# for debug messages
FS_MOUNTED=0;		# 0 for not mounted, 1 for mounted, 2 for multimounted
MOUNTPOINT=/dev/cgroup_controllers;	# Just to initialize
TARGET=/dev/cgroup_controllers;
CONTROLLERS=cpu,memory;
NUM_MOUNT=1;		# Number of places to be mounted on
MULTIMOUNT=false;	# mounted at on epoint only
debug()
{
	# Function parameter is the string to print out
	if $DEBUG
	then
		echo SH:DBG: $1;
	fi
}

check_mount_fs ()
{
	local NUM_MOUNT=0;
	CGROUP=`cat /proc/mounts|grep -w cgroup|tr -s [:space:]|cut -d" " -f3`;

	# get first word in case of multiple mounts
	CGROUP=`echo $CGROUP|cut -d" " -f1`;

	debug "check_mount_fs(): CGROUP is $CGROUP";
	if [ "$CGROUP" = "cgroup" ]
	then
		NUM_MOUNT=`cat /proc/mounts|grep -w cgroup|wc -l`;
		debug "check_mount_fs(): fs mounted at $NUM_MOUNT places";

		if [ $NUM_MOUNT -eq 1 ]
		then
			FS_MOUNTED=1;
		else
			# Any number of mounts is multi mount
			FS_MOUNTED=2;
		fi;
		return 0;	# True
	else
		FS_MOUNTED=0;
		return 1;	# false
	fi
}

umount_fs ()
{
	while check_mount_fs
	do
		PROC_ENTRY=`cat /proc/mounts|grep cgroup|tr -s [:space:]|cut -d" " -f2`;
		# Get first mountpoint in case of multiple mounts
		PROC_ENTRY=`echo $PROC_ENTRY|cut -d" " -f1`;
		if [ ! -z "$PROC_ENTRY" ]
		then
			TARGET=$PROC_ENTRY;
			# Need to take care if there are tasks running in any group ??
			# Also need to care if cpu and memory are mounted at different places
			rmdir $TARGET/* 2> /dev/null ;
			umount $TARGET;
			rmdir  $TARGET;
			debug "umounted $TARGET";
		fi;
	done
	FS_MOUNTED=0;
	TARGET=/dev/cgroup_controllers;	#??
	echo "Cleanup done";
}

# Check if kernel is not having any of the controllers enabled
no_controllers()
{
	CPU="";
	MEMORY="";
	if [ -e /proc/cgroups ]
	then
		CPU=`cat /proc/cgroups|grep -w cpu|cut -f1`;
		MEMORY=`cat /proc/cgroups|grep -w memory|cut -f1`;
	fi;

	if [ ! -z $CPU ] && [ ! -z $MEMORY ]
	then
		CONTROLLERS=$CPU,$MEMORY ;
		return 1;	# false
	elif [ ! -z $CPU ]
	then
		CONTROLLERS=$CPU ;
		return 1;	# false
	elif [ ! -z $MEMORY ]
	then
		CONTROLLERS=$MEMORY ;
{'fraction_non_alphanumeric': 0.11641509433962265, 'fraction_numerical': 0.010943396226415094, 'mean_word_length': 3.65, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '2728846', 'n_tokens_mistral': 2119, 'n_tokens_neox': 1952, 'n_words': 652}