Skip to content

Commit

Permalink
lib: c: global_set: handle DEFINE_SRCU
Browse files Browse the repository at this point in the history
  • Loading branch information
evdenis committed Jun 29, 2018
1 parent 6515c12 commit edcbc4b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
11 changes: 8 additions & 3 deletions lib/C/GlobalSet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ with 'C::Parse';
has '+set' => (isa => 'ArrayRef[C::Global]');

my %type_alias = (
DEFINE_SPINLOCK => 'spinlock_t',
DEFINE_MUTEX => 'struct mutex',
DEFINE_SPINLOCK => 'spinlock_t',
DEFINE_MUTEX => 'struct mutex',
DEFINE_SRCU => 'struct srcu_struct',
DEFINE_STATIC_SRCU => {
modifier => 'static',
type => 'struct srcu_struct'
},
DEFINE_RWLOCK => 'rwlock_t',
DECLARE_WAIT_QUEUE_HEAD => 'wait_queue_head_t',
DECLARE_WORK => 'struct work_struct',
Expand Down Expand Up @@ -100,7 +105,7 @@ sub parse
|
(?<type>(?>${simple_type}|${complex_type})\(${s}*+\*${s}*+${name}${array}?${s}*+\)${s}*+${fargs})(*SKIP)${optional_asm}${optional_init}
|
(?<type>\b(?:DEFINE_(?:SPINLOCK|RWLOCK|MUTEX)|LIST_HEAD)|DECLARE_WAIT_QUEUE_HEAD)${s}*+\(${s}*+${name}${s}*+\)
(?<type>\b(?:DEFINE_(?:SPINLOCK|RWLOCK|MUTEX|SRCU|STATIC_SRCU)|LIST_HEAD)|DECLARE_WAIT_QUEUE_HEAD)${s}*+\(${s}*+${name}${s}*+\)
|
(?<type>\bDEFINE_DEBUGFS_ATTRIBUTE)${s}*+\(${s}*+${name}${s}*+,[^)]++\)
|
Expand Down
21 changes: 14 additions & 7 deletions t/parse/GlobalSet.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use warnings;
use strict;

use Test::More tests => 28;
use Test::More tests => 29;
use Test::Deep;

use C::GlobalSet;
Expand All @@ -15,7 +15,9 @@ $g{$_->name} = $_ foreach @{$set->set};

cmp_deeply(
[sort keys %g],
[qw(chroot_count cpu_stop current_stack_pointer current_task fs_type read_f socket_update_slock unix_socket_table)],
[
qw(chroot_count chroot_srcu cpu_stop current_stack_pointer current_task fs_type read_f socket_update_slock unix_socket_table)
],
'globals'
);

Expand All @@ -24,8 +26,9 @@ is($g{fs_type}->type, 'struct file_system_type ', 'type test 2');
is($g{socket_update_slock}->type, 'spinlock_t', 'type test 3');
is($g{current_task}->type, 'struct task_struct *', 'type test 4');
is($g{read_f}->type, 'int (*read_f[SYM_NUM]) (struct policydb *p, struct hashtab *h, void *fp)', 'type test 5');
is($g{current_stack_pointer}->type, 'unsigned long ', 'type test 6');
is($g{chroot_count}->type, 'atomic_t ', 'type test 7');
is($g{current_stack_pointer}->type, 'unsigned long ', 'type test 6');
is($g{chroot_count}->type, 'atomic_t ', 'type test 7');
is($g{chroot_srcu}->type, 'struct srcu_struct', 'type test 8');

ok($g{unix_socket_table}->extern, 'extern test true 1');
ok($g{current_task}->extern, 'extern test true 2');
Expand Down Expand Up @@ -69,8 +72,9 @@ is($g{chroot_count}->initializer, 'ATOMIC_INIT(0)', 'initializer test 5');
cmp_deeply(
$set->ids,
bag(
["unix_socket_table"], ["fs_type"], ["socket_update_slock"], ["current_task"],
["cpu_stop"], ["read_f"], ["current_stack_pointer"], ["chroot_count"]
["unix_socket_table"], ["fs_type"], ["socket_update_slock"], ["current_task"],
["cpu_stop"], ["read_f"], ["current_stack_pointer"], ["chroot_count"],
["chroot_srcu"]
),
'ids'
);
Expand All @@ -90,7 +94,8 @@ cmp_deeply(
"sens_read", "cat_read"
],
["_ASM_SP"],
["atomic_t", "__read_mostly", "ATOMIC_INIT"]
["atomic_t", "__read_mostly", "ATOMIC_INIT"],
["DEFINE_SRCU"]
),
'tags'
);
Expand Down Expand Up @@ -127,3 +132,5 @@ static int (*read_f[SYM_NUM]) (struct policydb *p, struct hashtab *h, void *fp)
register unsigned long current_stack_pointer asm(_ASM_SP);
atomic_t chroot_count __read_mostly = ATOMIC_INIT(0);
DEFINE_SRCU(chroot_srcu);

0 comments on commit edcbc4b

Please sign in to comment.