Path: blob/main/system/lib/wasmfs/fuzzer/workload.h
6175 views
// Copyright 2021 The Emscripten Authors. All rights reserved.1// Emscripten is available under two separate licenses, the MIT license and the2// University of Illinois/NCSA Open Source License. Both these licenses can be3// found in the LICENSE file.45// This file defines fuzzer workloads which primarily fuzz multi-threaded6// operations.78#pragma once910#include "parameters.h"11#include "random.h"12#include <assert.h>13#include <chrono>14#include <cstdlib>15#include <iostream>16#include <optional>17#include <stdio.h>18#include <string>19#include <thread>20#include <unistd.h>21#include <unordered_map>2223namespace wasmfs {2425// This abstract class defines a fuzzer workload. It sets up a series of file26// system operations and then validates that the expected outcome is observed.27class Workload {28public:29Workload(Random& rand) : rand(rand) {}30virtual ~Workload() = default;3132// This function generates a workload based on a Random seed. It will test a33// file system property, using any required syscalls.34virtual void execute() = 0;3536protected:37Random& rand;38};3940// This workload class attempts to fuzz for tearing in reads and writes.41// This should validate that writes are atomic (i.e. that a read interleaved42// between two writes should not read a portion of the first write and a portion43// of the second write). Writer threads should write a uniform string of the44// same character. Reader threads should validate that file content is not45// intermixed (it should check that all characters in the file content are the46// same).47class ReadWrite : public Workload {4849public:50ReadWrite(Random& rand) : Workload(rand) {}5152void execute() override;5354private:55int fd;56// Work describes the list of strings being written to a test file.57std::vector<std::string> work;58std::atomic<bool> go{false};59std::atomic<bool> stop{false};6061bool isSame(std::vector<char>& target);62void reader();63void writer();64};65} // namespace wasmfs666768