1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
#! /usr/bin/perl -Idebian/tests/lib
# Ref: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=682156
use diagnostics;
use strict;
use warnings;
use AdduserTestsCommon;
my $startid = 22222;
my $size = 5000;
my $show = 50;
my $maxsecs = 120;
my $setup_secs = 240;
my $groupdel_secs = 60;
my ($secs, $isecs, $tsecs, $id);
my ($fp, $fs, $fg);
END {
}
# at the end of this, we will have 2*N groups, with N!+N memberships
open($fp, ">>", "/etc/passwd");
open($fs, ">>", "/etc/shadow");
open($fg, ">>", "/etc/group");
print "Creating users..\n";
$secs = time();
$tsecs = 0;
$id = $startid;
for (1..$size) {
my $username = "dgpu_$_";
$isecs = time();
print $fp
join(':', $username,'x', $id, $id, 'x', '/nonexistent', '/usr/sbin/nologin')."\n";
print $fs
join(':', $username, '!', $id, '','','','','')."\n";
print $fg
join(':', $username, 'x', $id, $username)."\n";
$isecs = time() - $isecs;
$tsecs += $isecs;
$id++;
print ".";
print "($_) [ ".($tsecs / $_)."s avg ]\n" if ($_ % $show == 0);
}
$secs = (time() - $secs) || 1;
ok($secs < $setup_secs, "created $size users in $secs seconds (< $setup_secs).");
print "Creating/populating groups..\n";
$secs = time();
$tsecs = 0;
for (1..$size) {
my $groupname = "dgpg_$_";
$isecs = time();
my $group_str = "";
for (1..$_) {
$group_str.="," if $group_str;
$group_str.="dgpu_$_";
}
print $fg join(':', $groupname, 'x', $id, $group_str)."\n";
$isecs = time() - $isecs;
$tsecs += $isecs;
$id++;
print ".";
print "($_) [ ".($tsecs / $_)."s avg ]\n" if ($_ % $show == 0);
}
$secs = (time() - $secs) || 1;
ok($secs < $setup_secs, "populated $size groups in $secs seconds (< $setup_secs).");
close($fp); close($fs); close($fg);
############ just for posterity; the "right" way is orders of magnitude too slow ##
#
# print "Creating users and groups..\n";
# $secs = time();
# $tsecs = 0;
# for (1..$size) {
# my $username = "dgpu_$_";
# my $groupname = "dgpg_$_";
# $isecs = time();
# ### ironically, our own tools are far too slow for this :)
# #
# # system('/usr/sbin/adduser',
# # '--stdoutmsglevel=error', '--stderrmsglevel=error',
# # '--comment="x"',
# # '--no-create-home',
# # '--disabled-password',
# # $username);
# # system('/usr/sbin/addgroup',
# # '--stdoutmsglevel=error', '--stderrmsglevel=error',
# # $groupname);
# # system('/usr/sbin/adduser',
# # '--stdoutmsglevel=error', '--stderrmsglevel=error',
# # "dgpu_$_",
# # $groupname)
# # for (1..$_);
# # system("/usr/sbin/groupmod", "-a", "-U", "dgpu_$_", $groupname) for (1..$_);
# #
# ##### then again, so is useradd :D
# system("/usr/sbin/groupadd", $groupname);
# system("/usr/sbin/useradd", "-M", "-l", $username);
# $isecs = time() - $isecs;
# $tsecs += $isecs;
# print ".";
# print "($_) [ ".($tsecs / $_)."s avg ]\n" if ($_ % $show == 0);
# }
# $secs = (time() - $secs) || 1;
# ok($secs, "created $size users/groups in $secs seconds.");
#
# print "Populating groups..\n";
# $secs = time();
# $tsecs = 0;
# for (1..$size) {
# $isecs = time();
# my $group_str = "";
# for (1..$_) {
# $group_str.="," if $group_str;
# $group_str.="dgpu_$_";
# }
# system("/usr/sbin/groupmod", "-U", $group_str, "dgpg_$_");
# $isecs = time() - $isecs;
# $tsecs += $isecs;
# print ".";
# print "($_) [ ".($tsecs / $_)."s avg ]\n" if ($_ % $show == 0);
# }
# $secs = (time() - $secs) || 1;
# ok($secs, "populated $size groups in $secs seconds.");
# these groups are wildly different sizes
my @groups = (3, int($size / 3), int($size * 2 / 3), $size - 2);
for (@groups) {
$secs = time();
my $groupname = "dgpg_$_";
assert_command_success('/usr/sbin/delgroup',
'--stdoutmsglevel=error', '--stderrmsglevel=error',
$groupname);
$secs = (time() - $secs) || 1;
ok($secs < $groupdel_secs, "delgroup $groupname took ${secs}s (< $groupdel_secs).");
}
for (@groups) {
$_ += 1;
$secs = time();
my $groupname = "dgpg_$_";
assert_command_success('/usr/sbin/groupdel', $groupname);
$secs = (time() - $secs) || 1;
ok($secs < $groupdel_secs, "groupdel $groupname took ${secs}s (< $groupdel_secs).");
}
# vim: tabstop=4 shiftwidth=4 expandtab
|