parent
58c4d1e78f
commit
c9bb95f395
|
@ -91,7 +91,7 @@ of 1k users per group, and test ubernss with such corpus.
|
||||||
|
|
||||||
```
|
```
|
||||||
$ zig-out/bin/turbonss-makecorpus
|
$ 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
|
$ ls -1hs passwd group
|
||||||
48M group
|
48M group
|
||||||
668K passwd
|
668K passwd
|
||||||
|
|
|
@ -27,7 +27,7 @@ const usage =
|
||||||
\\ --directory Write files to given directory (default: .)
|
\\ --directory Write files to given directory (default: .)
|
||||||
\\ --num-users Number of users (default: 10000)
|
\\ --num-users Number of users (default: 10000)
|
||||||
\\ --num-groups Number of groups (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 = "--directory", .kind = .arg },
|
||||||
.{ .name = "--num-users", .kind = .arg },
|
.{ .name = "--num-users", .kind = .arg },
|
||||||
.{ .name = "--num-groups", .kind = .arg },
|
.{ .name = "--num-groups", .kind = .arg },
|
||||||
.{ .name = "--avg-members", .kind = .arg },
|
.{ .name = "--max-members", .kind = .arg },
|
||||||
};
|
};
|
||||||
|
|
||||||
fn execute(
|
fn execute(
|
||||||
|
@ -79,7 +79,7 @@ fn execute(
|
||||||
|
|
||||||
const num_users = parseInt(stderr, myflags, "--num-users", 10000) orelse return error.User;
|
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 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 buf: [fs.MAX_PATH_BYTES]u8 = undefined;
|
||||||
var fixed = std.heap.FixedBufferAllocator.init(buf[0..]);
|
var fixed = std.heap.FixedBufferAllocator.init(buf[0..]);
|
||||||
|
@ -111,23 +111,22 @@ fn execute(
|
||||||
defer groupf.close();
|
defer groupf.close();
|
||||||
errdefer os.unlink(group_path) catch {};
|
errdefer os.unlink(group_path) catch {};
|
||||||
var group_wr = io.bufferedWriter(groupf.writer());
|
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;
|
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_users,
|
||||||
num_groups,
|
num_groups,
|
||||||
avg_members,
|
max_members,
|
||||||
dir,
|
dir,
|
||||||
}) catch {};
|
}) catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dump_passwd(wr: anytype, num_users: u64) error{IO}!void {
|
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_gecos: [PackedUser.max_gecos_len]u8 = undefined;
|
||||||
var buf_name: [PackedUser.max_name_len]u8 = undefined;
|
var buf_name: [PackedUser.max_name_len]u8 = undefined;
|
||||||
var buf_home: [PackedUser.max_home_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 name = fmt.bufPrint(buf_name[0..], "u_{d}", .{i}) catch unreachable;
|
||||||
const gecos = fmt.bufPrint(buf_gecos[0..], "User {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;
|
const home = fmt.bufPrint(buf_home[0..], "/home/{s}", .{name}) catch unreachable;
|
||||||
|
@ -143,20 +142,16 @@ 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 lw = io.bufferedWriter(wr);
|
||||||
var lwr = lw.writer();
|
var lwr = lw.writer();
|
||||||
var i: u32 = 1000000;
|
for (1000000..1000000 + num_groups) |i| {
|
||||||
while (i < 1000000 + num_groups) : (i += 1) {
|
|
||||||
lwr.print("g_{d}:x:{d}:", .{ i, i }) catch return error.IO;
|
lwr.print("g_{d}:x:{d}:", .{ i, i }) catch return error.IO;
|
||||||
var j: usize = 0;
|
for (0..(i % max_members)) |j| {
|
||||||
if (avg_members > 0) {
|
const user_idx = (i + j - 1) % num_users;
|
||||||
while (j < i % avg_members) : (j += 1) {
|
if (j != 0)
|
||||||
const user_idx = (i + j - 1) % num_users;
|
_ = lwr.write(",") catch return error.IO;
|
||||||
if (j != 0)
|
_ = lwr.print("u_{d}", .{1000000 + user_idx}) catch return error.IO;
|
||||||
_ = lwr.write(",") catch return error.IO;
|
|
||||||
_ = lwr.print("u_{d}", .{1000000 + user_idx}) catch return error.IO;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ = lwr.write("\n") catch return error.IO;
|
_ = lwr.write("\n") catch return error.IO;
|
||||||
}
|
}
|
||||||
|
@ -240,14 +235,14 @@ test "turbonss-makecorpus: simple OK case" {
|
||||||
"1",
|
"1",
|
||||||
"--num-groups",
|
"--num-groups",
|
||||||
"1",
|
"1",
|
||||||
"--avg-members",
|
"--max-members",
|
||||||
"1",
|
"1",
|
||||||
"--directory",
|
"--directory",
|
||||||
tmp_path,
|
tmp_path,
|
||||||
};
|
};
|
||||||
|
|
||||||
try execute(stdout.writer(), stderr.writer(), args);
|
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, "");
|
try testing.expectEqualStrings(stdout.items, "");
|
||||||
|
|
||||||
const passwd_fname = try fs.path.join(allocator, &[_][]const u8{ tmp_path, "passwd" });
|
const passwd_fname = try fs.path.join(allocator, &[_][]const u8{ tmp_path, "passwd" });
|
||||||
|
|
Loading…
Reference in New Issue