1 // Copyright (C) 2021 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #include <pthread.h> 18 19 #include <memory> 20 #include <string> 21 #include <thread> 22 23 #include <ditto/result.h> 24 #include <ditto/sampler.h> 25 #include <ditto/syscall.h> 26 27 namespace dittosuite { 28 29 enum class Order { kSequential, kRandom }; 30 enum class Reseeding { kOnce, kEachRoundOfCycles, kEachCycle }; 31 32 class Instruction { 33 public: 34 explicit Instruction(SyscallInterface& syscall, const std::string& name, int repeat); 35 virtual ~Instruction() = default; 36 37 virtual void SetUp(); 38 void Run(); 39 void RunSynchronized(pthread_barrier_t* barrier); 40 std::thread SpawnThread(pthread_barrier_t* barrier); 41 virtual void TearDown(); 42 43 virtual std::unique_ptr<Result> CollectResults(const std::string& prefix); 44 45 static void SetAbsolutePathKey(int absolute_path_key); 46 47 protected: 48 virtual void SetUpSingle(); 49 virtual void RunSingle() = 0; 50 virtual void TearDownSingle(); 51 52 std::string GetAbsolutePath(); 53 54 SyscallInterface& syscall_; 55 static int absolute_path_key_; 56 std::string name_; 57 int repeat_; 58 TimeSampler time_sampler_; 59 }; 60 61 } // namespace dittosuite 62