avg-members -> max-members

that's what it really means.
This commit is contained in:
Motiejus Jakštys 2023-04-13 11:18:29 +03:00
parent 58c4d1e78f
commit c9bb95f395
2 changed files with 17 additions and 22 deletions

View File

@ -91,7 +91,7 @@ of 1k users per group, and test ubernss with such corpus.
```
$ zig-out/bin/turbonss-makecorpus
wrote users=10000 groups=10000 avg-members=1000 to .
wrote users=10000 groups=10000 max-members=1000 to .
$ ls -1hs passwd group
48M group
668K passwd

View File

@ -27,7 +27,7 @@ const usage =
\\ --directory Write files to given directory (default: .)
\\ --num-users Number of users (default: 10000)
\\ --num-groups Number of groups (default: 10000)
\\ --avg-members Average members per group (default: 1000)
\\ --max-members Average members per group (default: 1000)
\\
;
@ -54,7 +54,7 @@ const options = &[_]flags.Flag{
.{ .name = "--directory", .kind = .arg },
.{ .name = "--num-users", .kind = .arg },
.{ .name = "--num-groups", .kind = .arg },
.{ .name = "--avg-members", .kind = .arg },
.{ .name = "--max-members", .kind = .arg },
};
fn execute(
@ -79,7 +79,7 @@ fn execute(
const num_users = parseInt(stderr, myflags, "--num-users", 10000) orelse return error.User;
const num_groups = parseInt(stderr, myflags, "--num-groups", 10000) orelse return error.User;
const avg_members = parseInt(stderr, myflags, "--avg-members", 1000) orelse return error.User;
const max_members = parseInt(stderr, myflags, "--max-members", 1000) orelse return error.User;
var buf: [fs.MAX_PATH_BYTES]u8 = undefined;
var fixed = std.heap.FixedBufferAllocator.init(buf[0..]);
@ -111,23 +111,22 @@ fn execute(
defer groupf.close();
errdefer os.unlink(group_path) catch {};
var group_wr = io.bufferedWriter(groupf.writer());
try dump_group(group_wr.writer(), num_users, num_groups, avg_members);
try dump_group(group_wr.writer(), num_users, num_groups, max_members);
group_wr.flush() catch return error.IO;
stderr.print("wrote users={d} groups={d} avg-members={d} to {s}\n", .{
stderr.print("wrote users={d} groups={d} max-members={d} to {s}\n", .{
num_users,
num_groups,
avg_members,
max_members,
dir,
}) catch {};
}
fn dump_passwd(wr: anytype, num_users: u64) error{IO}!void {
var i: u32 = 1000000;
var buf_gecos: [PackedUser.max_gecos_len]u8 = undefined;
var buf_name: [PackedUser.max_name_len]u8 = undefined;
var buf_home: [PackedUser.max_home_len]u8 = undefined;
while (i < 1000000 + num_users) : (i += 1) {
for (1000000..1000000 + num_users) |i| {
const name = fmt.bufPrint(buf_name[0..], "u_{d}", .{i}) catch unreachable;
const gecos = fmt.bufPrint(buf_gecos[0..], "User {d}", .{i}) catch unreachable;
const home = fmt.bufPrint(buf_home[0..], "/home/{s}", .{name}) catch unreachable;
@ -143,21 +142,17 @@ fn dump_passwd(wr: anytype, num_users: u64) error{IO}!void {
}
}
fn dump_group(wr: anytype, num_users: u64, num_groups: u64, avg_members: u32) error{IO}!void {
fn dump_group(wr: anytype, num_users: u64, num_groups: u64, max_members: u32) error{IO}!void {
var lw = io.bufferedWriter(wr);
var lwr = lw.writer();
var i: u32 = 1000000;
while (i < 1000000 + num_groups) : (i += 1) {
for (1000000..1000000 + num_groups) |i| {
lwr.print("g_{d}:x:{d}:", .{ i, i }) catch return error.IO;
var j: usize = 0;
if (avg_members > 0) {
while (j < i % avg_members) : (j += 1) {
for (0..(i % max_members)) |j| {
const user_idx = (i + j - 1) % num_users;
if (j != 0)
_ = lwr.write(",") catch return error.IO;
_ = lwr.print("u_{d}", .{1000000 + user_idx}) catch return error.IO;
}
}
_ = lwr.write("\n") catch return error.IO;
}
lw.flush() catch return error.IO;
@ -240,14 +235,14 @@ test "turbonss-makecorpus: simple OK case" {
"1",
"--num-groups",
"1",
"--avg-members",
"--max-members",
"1",
"--directory",
tmp_path,
};
try execute(stdout.writer(), stderr.writer(), args);
try testing.expectStringStartsWith(stderr.items, "wrote users=1 groups=1 avg-members=1 to /");
try testing.expectStringStartsWith(stderr.items, "wrote users=1 groups=1 max-members=1 to /");
try testing.expectEqualStrings(stdout.items, "");
const passwd_fname = try fs.path.join(allocator, &[_][]const u8{ tmp_path, "passwd" });