add: proc|sys fs format_checker (tool)

This commit is contained in:
Ken Sato
2017-11-22 09:39:48 +09:00
parent 66f44e77af
commit 4e7069d499
38 changed files with 387 additions and 0 deletions

View File

@ -0,0 +1,164 @@
#!/usr/bin/perl
use utf8;
use Encode qw/encode decode/;
sub count_occurence {
my $err_num = 0;
my $fn = shift();
my @pattern = @_;
my $lineno = 0;
if (open(DATAFILE, "< $fn")) {
while (my $line = <DATAFILE>) {
my $check = 0;
chomp $line;
for (my $i = 0; $i <= $#pattern; $i++) {
if ($line =~ /$pattern[$i]/) {
$freq[$filecnt][$i]++;
$check = 1;
if ($loc[$i][$blockno] == 1) {
$blockno++;
}
$loc[$i][$blockno] = 1;
last;
}
}
$lineno++;
if ($check == 0) {
$no_match[$err_num] = $lineno;
$err_num++;
}
}
} else {
return -1;
}
return $err_num;
}
if (@ARGV != 1) {
print "Usage: file_format_check.pl filename\n";
exit(1);
}
my @pattern1 = ();
my @pattern2 = ();
my $n = 1;
my $checkflg = 0;
open(DATAFILE, "< $ARGV[0]") or die("Error:$!");
while (my $line = <DATAFILE>) {
chomp $line;
if ($n == 1) {
$checkfilepath = $line;
} elsif ($n == 2) {
$checkmode = $line;
} elsif ($checkflg == 1) {
push @pattern2, $line;
} elsif ($line =~ /^$/) {
$checkflg = 1;
} else {
push @pattern1, $line;
push @pattern_check, 0;
}
$n++;
}
my $fname = "";
my $fnameflg = 0;
my $rtn_code = 0;
my $total_errcnt = 0;
my $my_tid = $$;
my $tmp_cmdls = "ls $checkfilepath";
my $cmdls = "ls $checkfilepath";
$cmdls =~ s/#pid#/$my_tid/g;
if ($tmp_cmdls eq $cmdls) {
$fnameflg = 1;
}
if ($checkmode < 1 || $checkmode > 3) {
$checkmode = 1;
}
my $cmdexec = `$cmdls`;
my @list = split(/\n/, $cmdexec);
$filecnt = 0;
foreach my $parts(@list) {
$errcnt = 0;
$freq = ();
$loc = ();
$no_match = ();
$blockno = 0;
# パターン検証サブルーチンコール
my $rtn_code = &count_occurence($parts, @pattern1, @pattern2);
if ($rtn_code == -1) {
$err_msg = "$err_msg Err(ファイルが存在しませんでした)\n";
$errcnt = 1;
} else {
for (my $i = 0; $i <= $#no_match; $i++) {
$err_msg = "$err_msg Err(対象ファイルの$no_match[$i]行目がどのパターンにも合致しませんでした)\n";
$errcnt++;
}
# pattern1
if ($checkmode == 1) {
for (my $i = 0; $i <= $#pattern1; $i++) {
if ($freq[$filecnt][$i] == 0) {
$err_msg = "$err_msg Err(チェックパターン($pattern1[$i])に一致する行が存在しませんでした)\n";
$errcnt++;
} elsif ($freq[$filecnt][$i] > 1) {
$err_msg = "$err_msg Err(チェックパターン($pattern1[$i])に一致する行が複数回存在しました)\n";
$errcnt++;
}
}
# pattern2
} elsif ($checkmode == 2) {
for (my $i = 0; $i <= $#pattern1; $i++) {
if ($freq[$filecnt][$i] == 0) {
$err_msg = "$err_msg Err(チェックパターン($pattern1[$i])に一致する行が存在しませんでした)\n";
$errcnt++;
}
}
# pattern3
} elsif ($checkmode == 3) {
$count = $freq[$filecnt][0];
for (my $i = 0; $i <= $#pattern1; $i++) {
if ($freq[$filecnt][$i] == 0) {
$err_msg = "$err_msg Err(全ブロックでチェックパターン($pattern1[$i])が存在しませんでした)\n";
$errcnt++;
} elsif ($freq[$filecnt][$i] != $count) {
for (my $j = 0; $j <= $blockno; $j++) {
if ($loc[$i][$j] != 1) {
$bno = $j + 1;
$err_msg = "$err_msg Err(${bno}ブロック目でチェックパターン($pattern1[$i])に一致する行が存在しませんでした)\n";
$errcnt++;
}
}
}
}
}
}
if ($fnameflg == 0) {
$fname = $checkfilepath;
} else {
$fname = $parts;
}
if ($errcnt == 0) {
print "[OK] $fname\n";
} else {
print "[NG] $fname\n";
$err_msg = encode('UTF-8', $err_msg);
print "$err_msg";
system("cat $parts > NG_`basename $ARGV[0]`");
}
$total_errcnt = $total_errcnt + $errcnt;
$filecnt++;
}
if ($total_errcnt == 0) {
exit(0);
} else {
exit($total_errcnt);
}

View File

@ -0,0 +1,14 @@
#!/bin/sh
#file_format_check.sh
filename="./input"
if [ "x$1" != "x" ]; then
filename=$1
fi
cat /dev/null > outfile
cat ${filename} | while read line
do
./file_format_check.pl $line >> outfile
done

View File

@ -0,0 +1,35 @@
./proc/proc_stat
./proc/proc_pid_cgroup
./proc/proc_pid_cmdline
./proc/proc_pid_cpuset
./proc/proc_pid_maps
./proc/proc_pid_smaps
./proc/proc_pid_stat
./proc/proc_pid_status
./proc/proc_pid_task_thid_stat
./sys/cpu_offline
./sys/cpu_online
./sys/cpu_possible
./sys/cpu_present
./sys/cpu_cpu_online
./sys/cpu_cpu_cache_index_level
./sys/cpu_cpu_cache_index_type
./sys/cpu_cpu_cache_index_size
./sys/cpu_cpu_cache_index_coherency_line_size
./sys/cpu_cpu_cache_index_number_of_sets
./sys/cpu_cpu_cache_index_physical_line_partition
./sys/cpu_cpu_cache_index_ways_of_associativity
./sys/cpu_cpu_cache_index_shared_cpu_map
./sys/cpu_cpu_cache_index_shared_cpu_list
./sys/cpu_cpu_topology_physical_package_id
./sys/cpu_cpu_topology_core_id
./sys/cpu_cpu_topology_core_siblings
./sys/cpu_cpu_topology_core_siblings_list
./sys/cpu_cpu_topology_thread_siblings
./sys/cpu_cpu_topology_thread_siblings_list
./sys/node_online
./sys/node_possible
./sys/node_node_distance
./sys/node_node_cpumap
./sys/pci_local_cpus
./sys/pci_local_cpulist

View File

@ -0,0 +1,4 @@
/proc/#pid#/cgroup
1
^[\d]+[:][\w=,]+[:][/\w\-.@]+

View File

@ -0,0 +1,3 @@
/proc/#pid#/cmdline
1
^[\s\w/\-\(\).=:\[\]@]+

View File

@ -0,0 +1,4 @@
/proc/#pid#/cpuset
1
^[/][\w/\-]*

View File

@ -0,0 +1,3 @@
/proc/#pid#/maps
2
^[\da-f]+[\-][\da-f]+\s[rwxsp\-]{4}\s[\da-f]+\s[\d]{2}[:][\d]{2}\s[\d]+([\s]+\[heap\]|[\s]+\[vdso\]|[\s]+\[stack\]|[\s]+\[stack:[\d]+\]|[\s]+\[vsyscall\]|[\s]+/[\w/\-.]+|\s)

View File

@ -0,0 +1,20 @@
/proc/#pid#/smaps
3
^[\da-f]+[\-][\da-f]+\s[rwxsp\-]{4}\s[\da-f]+\s[\d]{2}[:][\d]{2}\s[\d]+([\s]+\[heap\]|[\s]+\[vdso\]|[\s]+\[stack\]|[\s]+\[stack:[\d]+\]|[\s]+\[vsyscall\]|[\s]+/[\w/\-.]+|\s)
^Size:[\s]+[\d]+\skB
^Rss:[\s]+[\d]+\skB
^Pss:[\s]+[\d]+\skB
^Shared_Clean:[\s]+[\d]+\skB
^Shared_Dirty:[\s]+[\d]+\skB
^Private_Clean:[\s]+[\d]+\skB
^Private_Dirty:[\s]+[\d]+\skB
^Referenced:[\s]+[\d]+\skB
^Anonymous:[\s]+[\d]+\skB
^AnonHugePages:[\s]+[\d]+\skB
^Swap:[\s]+[\d]+\skB
^KernelPageSize:[\s]+[\d]+\skB
^MMUPageSize:[\s]+[\d]+\skB
^Locked:[\s]+[\d]+\skB
^VmFlags:[\s]+([\l]{2}\s)*
^Nonlinear:[\s]+[\d]+\skB

View File

@ -0,0 +1,3 @@
/proc/#pid#/stat
1
^[\d]+\s\([\w/\-.:]+\)\s[R|S|D|T|t|X|Z]\s[\-]*[\d]+\s[\-]*[\d]+\s[\-]*[\d]+\s[\-]*[\d]+\s[\-]*[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\-]*[\d]+\s[\-]*[\d]+\s[\-]*[\d]+\s[\-]*[\d]+\s[\-]*[\d]+\s[\-]*[\d]+\s[\d]+\s[\d]+\s[\-]*[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\-]*[\d]+\s[\-]*[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\-]*[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\-]*[\d]+

View File

@ -0,0 +1,44 @@
/proc/#pid#/status
1
^Name:\t[\w]+
^State:\t(R \(running\)|S \(sleeping\)|D \(disk sleep\)|T \(stopped\)|t \(tracing stop\)|X \(dead\)|Z \(zombie\))
^Tgid:\t[\d]+
^Ngid:\t[\d]+
^Pid:\t[\d]+
^PPid:\t[\d]+
^TracerPid:\t[\d]+
^Uid:\t[\d]+\t[\d]+\t[\d]+\t[\d]+
^Gid:\t[\d]+\t[\d]+\t[\d]+\t[\d]+
^FDSize:\t[0-9]+
^Groups:\t(([\d]+)(\s))*
^VmPeak:[\s]+[\d]{1,8}\skB
^VmSize:[\s]+[\d]{1,8}\skB
^VmLck:[\s]+[\d]{1,8}\skB
^VmPin:[\s]+[\d]{1,8}\skB
^VmHWM:[\s]+[\d]{1,8}\skB
^VmRSS:[\s]+[\d]{1,8}\skB
^VmData:[\s]+[\d]{1,8}\skB
^VmStk:[\s]+[\d]{1,8}\skB
^VmExe:[\s]+[\d]{1,8}\skB
^VmLib:[\s]+[\d]{1,8}\skB
^VmPTE:[\s]+[\d]{1,8}\skB
^VmSwap:[\s]+[\d]{1,8}\skB
^Threads:\t[\d]+
^SigQ:\t[\d]+/[\d]+
^SigPnd:\t[\da-f]+
^ShdPnd:\t[\da-f]+
^SigBlk:\t[\da-f]+
^SigIgn:\t[\da-f]+
^SigCgt:\t[\da-f]+
^CapInh:\t[\da-f]+
^CapPrm:\t[\da-f]+
^CapEff:\t[\da-f]+
^CapBnd:\t[\da-f]+
^Cpus_allowed:\t[\da-f,]+
^Cpus_allowed_list:\t[\d,\-]+
^Mems_allowed:\t[\da-f,]+
^Mems_allowed_list:\t[\d,\-]+
^voluntary_ctxt_switches:\t[\d]+
^nonvoluntary_ctxt_switches:\t[\d]+
^Seccomp:[\s]+[\d]+

View File

@ -0,0 +1,3 @@
/proc/#pid#/task/#pid#/stat
1
^[\d]+\s\([\w]+\)\s[R|S|D|T|t|X|Z]\s[\-]*[\d]+\s[\-]*[\d]+\s[\-]*[\d]+\s[\-]*[\d]+\s[\-]*[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\-]*[\d]+\s[\-]*[\d]+\s[\-]*[\d]+\s[\-]*[\d]+\s[\-]*[\d]+\s[\-]*[\d]+\s[\d]+\s[\d]+\s[\-]*[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\-]*[\d]+\s[\-]*[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\-]*[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\d]+\s[\-]*[\d]+

View File

@ -0,0 +1,12 @@
/proc/stat
1
^cpu\s((\s)([\d]+)){10}
^intr((\s)([\d]+))+
^ctxt\s[\d]+
^btime\s[\d]+
^processes\s[\d]+
^procs_running\s[\d]+
^procs_blocked\s[\d]+
^softirq((\s)([\d]+)){11}
^cpu[\d]+((\s)([\d]+)){10}

View File

@ -0,0 +1,3 @@
/sys/devices/system/cpu/cpu0/cache/index[0-1]/coherency_line_size
1
^[\d]+

View File

@ -0,0 +1,3 @@
/sys/devices/system/cpu/cpu0/cache/index[0-1]/level
1
^[\d]+

View File

@ -0,0 +1,3 @@
/sys/devices/system/cpu/cpu0/cache/index[0-1]/number_of_sets
1
^[\d]+

View File

@ -0,0 +1,3 @@
/sys/devices/system/cpu/cpu0/cache/index[0-1]/physical_line_partition
1
^[\d]+

View File

@ -0,0 +1,3 @@
/sys/devices/system/cpu/cpu0/cache/index[0-1]/shared_cpu_list
1
^[\d,\-]+

View File

@ -0,0 +1,3 @@
/sys/devices/system/cpu/cpu0/cache/index[0-1]/shared_cpu_map
1
^[\da-f,]+

View File

@ -0,0 +1,3 @@
/sys/devices/system/cpu/cpu0/cache/index[0-1]/size
1
^[\d]+K

View File

@ -0,0 +1,3 @@
/sys/devices/system/cpu/cpu0/cache/index[0-1]/type
1
^(Instruction|Data|Unified|Unknown)

View File

@ -0,0 +1,3 @@
/sys/devices/system/cpu/cpu0/cache/index[0-1]/ways_of_associativity
1
^[\d]+

View File

@ -0,0 +1,3 @@
/sys/devices/system/cpu/cpu1/online
1
^[0-1]

View File

@ -0,0 +1,3 @@
/sys/devices/system/cpu/cpu0/topology/core_id
1
^[\d]+

View File

@ -0,0 +1,3 @@
/sys/devices/system/cpu/cpu0/topology/core_siblings
1
^[\da-f,]+

View File

@ -0,0 +1,3 @@
/sys/devices/system/cpu/cpu0/topology/core_siblings_list
1
^[\d,\-]+

View File

@ -0,0 +1,3 @@
/sys/devices/system/cpu/cpu0/topology/physical_package_id
1
^[\d]+

View File

@ -0,0 +1,3 @@
/sys/devices/system/cpu/cpu0/topology/thread_siblings
1
^[\da-f,]+

View File

@ -0,0 +1,3 @@
/sys/devices/system/cpu/cpu0/topology/thread_siblings_list
1
^[\d,\-]+

View File

@ -0,0 +1,3 @@
/sys/devices/system/cpu/offline
2
^[\d,\-]*

View File

@ -0,0 +1,3 @@
/sys/devices/system/cpu/online
1
^[\d,\-]+

View File

@ -0,0 +1,3 @@
/sys/devices/system/cpu/possible
1
^[\d,\-]+

View File

@ -0,0 +1,3 @@
/sys/devices/system/cpu/present
1
^[\d,\-]+

View File

@ -0,0 +1,3 @@
/sys/devices/system/node/node0/cpumap
1
^[\d,\-]+

View File

@ -0,0 +1,3 @@
/sys/devices/system/node/node0/distance
1
^[\d\s]+

View File

@ -0,0 +1,3 @@
/sys/devices/system/node/online
1
^[\d,\-]+

View File

@ -0,0 +1,3 @@
/sys/devices/system/node/possible
1
^[\d,\-]+

View File

@ -0,0 +1,3 @@
/sys/devices/pci0000:00/0000:00:00.0/local_cpulist
1
^[\d,\-]+

View File

@ -0,0 +1,3 @@
/sys/devices/pci0000:00/0000:00:00.0/local_cpus
1
^[\da-f,]+