Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

steps:
- uses: actions/checkout@v3
- run: sudo apt-get install -y libparted-dev libudev-dev
- run: sudo apt-get update && sudo apt-get install -y libparted-dev libudev-dev
- run: make all extra

- if: matrix.volume == 'relative-path'
Expand Down Expand Up @@ -70,8 +70,10 @@ jobs:
- name: Cleanup loop device
if: always()
run: |
sudo losetup -d ${{ steps.loop.outputs.dev }}
rm dummy.img
if [ -n "${{ steps.loop.outputs.dev }}" ]; then
sudo losetup -d ${{ steps.loop.outputs.dev }}
fi
rm -f dummy.img

MacOS:
strategy:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ f3write: libutils.o utils.o libflow.o f3write.o
f3read: libutils.o utils.o libflow.o f3read.o
$(CC) -o $@ $^ $(LDFLAGS) -lm

f3probe: libutils.o libdevs.o libprobe.o f3probe.o
$(CC) -o $@ $^ $(LDFLAGS) -ludev
f3probe: libutils.o libflow.o libdevs.o libprobe.o f3probe.o
$(CC) -o $@ $^ $(LDFLAGS) -lm -ludev

f3brew: libutils.o libflow.o libdevs.o f3brew.o
$(CC) -o $@ $^ $(LDFLAGS) -lm -ludev
Expand Down
11 changes: 7 additions & 4 deletions f3brew.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#define _POSIX_C_SOURCE 200112L
#define _XOPEN_SOURCE 600

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -323,8 +326,8 @@ static void test_write_blocks(struct device *dev,
first_block, last_block);
fflush(stdout);

init_flow(&fw, block_size, total_size, max_write_rate, show_progress,
NULL);
init_flow(&fw, block_size, total_size, max_write_rate,
show_progress ? printf_flush_cb : dummy_cb, 0, NULL);

assert(!gettimeofday(&t1, NULL));
write_blocks(dev, &fw, first_block, last_block);
Expand Down Expand Up @@ -498,8 +501,8 @@ static void test_read_blocks(struct device *dev,
printf("Reading blocks from 0x%" PRIx64 " to 0x%" PRIx64 ":\n",
first_block, last_block);

init_flow(&fw, block_size, total_size, max_read_rate, show_progress,
NULL);
init_flow(&fw, block_size, total_size, max_read_rate,
show_progress ? printf_flush_cb : dummy_cb, 0, NULL);

assert(!gettimeofday(&t1, NULL));
read_blocks(dev, &fw, first_block, last_block, &stats);
Expand Down
3 changes: 3 additions & 0 deletions f3fix.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#define _POSIX_C_SOURCE 200112L
#define _XOPEN_SOURCE 600

#include <stdbool.h>
#include <assert.h>
#include <argp.h>
Expand Down
42 changes: 19 additions & 23 deletions f3probe.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#define _POSIX_C_SOURCE 200809L
#define _POSIX_C_SOURCE 200112L
#define _XOPEN_SOURCE 600

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <argp.h>
#include <stdbool.h>
#include <assert.h>
#include <inttypes.h>
#include <sys/time.h>
#include <unistd.h>

#include "version.h"
#include "libprobe.h"
Expand Down Expand Up @@ -53,6 +54,8 @@ static struct argp_option options[] = {
"Time reads, writes, and resets", 0},
{"verbose", 'v', NULL, 0,
"Show detailed progress", 0},
{"show-progress", 'p', "NUM", 0,
"Show progress if NUM is not zero", 0},
{ 0 }
};

Expand All @@ -69,6 +72,7 @@ struct args {
bool min_mem;
bool time_ops;
bool verbose;
bool show_progress;

/* Geometry. */
uint64_t real_size_byte;
Expand Down Expand Up @@ -165,6 +169,10 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
args->verbose = true;
break;

case 'p':
args->show_progress = !!arg_to_ll_bytes(state, arg);
break;

case ARGP_KEY_INIT:
args->filename = NULL;
break;
Expand Down Expand Up @@ -196,12 +204,6 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)

static struct argp argp = {options, parse_opt, adoc, doc, NULL, NULL, NULL};

static void dummy_probe_progress(const char *format, ...)
{
/* Do nothing */
UNUSED(format);
}

struct unit_test_item {
uint64_t real_size_byte;
uint64_t fake_size_byte;
Expand Down Expand Up @@ -277,8 +279,8 @@ static int unit_test(const char *filename)
assert(dev);
max_probe_blocks = probe_device_max_blocks(dev);
assert(!probe_device(dev, &real_size_byte, &announced_size_byte,
&wrap, &cache_size_block, &block_order,
dummy_probe_progress));
&wrap, &cache_size_block, &block_order, dummy_cb,
false));
free_device(dev);
fake_type = dev_param_to_type(real_size_byte,
announced_size_byte, wrap, block_order);
Expand Down Expand Up @@ -329,18 +331,18 @@ static int unit_test(const char *filename)
static inline void report_size(const char *prefix, uint64_t bytes,
int block_order)
{
report_probed_size(printf_cb, prefix, bytes, block_order);
report_probed_size(0, printf_cb, prefix, bytes, block_order);
}

static inline void report_order(const char *prefix, int order)
{
report_probed_order(printf_cb, prefix, order);
report_probed_order(0, printf_cb, prefix, order);
}

static inline void report_cache(const char *prefix, uint64_t cache_size_block,
int block_order)
{
report_probed_cache(printf_cb, prefix, cache_size_block, block_order);
report_probed_cache(0, printf_cb, prefix, cache_size_block, block_order);
}

static void report_probe_time(const char *prefix, uint64_t usec)
Expand All @@ -358,15 +360,6 @@ static void report_ops(const char *op, uint64_t count, uint64_t time_us)
printf("%10s: %s / %" PRIu64 " = %s\n", op, str1, count, str2);
}

static void print_probe_progress(const char *format, ...)
{
va_list args;
va_start(args, format);
vprintf(format, args);
va_end(args);
fflush(stdout);
}

static int test_device(struct args *args)
{
struct timeval t1, t2;
Expand Down Expand Up @@ -421,7 +414,8 @@ static int test_device(struct args *args)
*/
assert(!probe_device(dev, &real_size_byte, &announced_size_byte,
&wrap, &cache_size_block, &block_order,
args->verbose ? print_probe_progress : dummy_probe_progress));
args->verbose ? printf_flush_cb : dummy_cb,
args->show_progress));
assert(!gettimeofday(&t2, NULL));

if (args->verbose) {
Expand Down Expand Up @@ -518,6 +512,8 @@ int main(int argc, char **argv)
.min_mem = false,
.time_ops = false,
.verbose = false,
/* If stdout isn't a terminal, suppress progress. */
.show_progress = isatty(STDOUT_FILENO),
.real_size_byte = 1ULL << 31,
.fake_size_byte = 1ULL << 34,
.wrap = 31,
Expand Down
2 changes: 1 addition & 1 deletion f3read.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ static void iterate_files(const char *path, const long *files,
UNUSED(end_at);

init_flow(&fw, get_block_size(path), get_total_size(path, files),
max_read_rate, progress, NULL);
max_read_rate, progress ? printf_flush_cb : dummy_cb, 0, NULL);
printf(" SECTORS "
" ok/corrupted/changed/overwritten\n");

Expand Down
2 changes: 1 addition & 1 deletion f3write.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ static int fill_fs(const char *path, long start_at, long end_at,
}

init_flow(&fw, get_block_size(path), free_space, max_write_rate,
progress, flush_chunk);
progress ? printf_flush_cb : dummy_cb, 0, flush_chunk);
assert(!gettimeofday(&t1, NULL));
for (i = start_at; i <= end_at; i++)
if (create_and_fill_file(path, i, GIGABYTES,
Expand Down
8 changes: 0 additions & 8 deletions libdevs.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ const char *dev_get_filename(struct device *dev);
* Methods
*/

/* One should use the following constant as the size of the buffer needed to
* batch writes or reads.
*
* It must be a power of 2 greater than, or equal to 2^20.
* The current value is 1MB.
*/
#define BIG_BLOCK_SIZE_BYTE (1 << 20)

int dev_read_blocks(struct device *dev, char *buf,
uint64_t first_pos, uint64_t last_pos);
int dev_write_blocks(struct device *dev, const char *buf,
Expand Down
Loading
Loading