10
10
11
11
#include " argparse/argparse.hpp"
12
12
#include " common/bustub_instance.h"
13
+ #include " common/config.h"
13
14
#include " common/exception.h"
14
15
#include " common/util/string_util.h"
15
16
#include " execution/check_options.h"
@@ -137,30 +138,30 @@ auto ProcessExtraOptions(const std::string &sql, bustub::BusTubInstance &instanc
137
138
auto expected_cols_proj = std::stoi (args[2 ]);
138
139
auto expected_cols_agg = std::stoi (args[3 ]);
139
140
// find agg & proj plan and test if the output schema has the expected number of columns
140
- auto lines = bustub::StringUtil::Split (result.str (), " \n " );
141
- for (auto &line : lines) {
142
- bustub::StringUtil::LTrim (&line);
143
- if (bustub::StringUtil::StartsWith (line, " Agg" )) {
144
- auto cols = bustub::StringUtil::Split (line, " ]," );
145
- if (cols.size () != 3 ) {
146
- fmt::print (" Agg plan wrong formatting!\n " );
147
- return false ;
148
- }
149
- for (int i = 0 ; i < 2 ; i++) {
150
- if (bustub::StringUtil::Count (cols[i], " \" ," )+1 > static_cast <size_t >(expected_cols_agg)) {
151
- fmt::print (" Agg wrong column pruning count!\n " );
152
- return false ;
153
- }
154
- }
155
- break ;
141
+ auto lines = bustub::StringUtil::Split (result.str (), " \n " );
142
+ for (auto &line : lines) {
143
+ bustub::StringUtil::LTrim (&line);
144
+ if (bustub::StringUtil::StartsWith (line, " Agg" )) {
145
+ auto cols = bustub::StringUtil::Split (line, " ]," );
146
+ if (cols.size () != 3 ) {
147
+ fmt::print (" Agg plan wrong formatting!\n " );
148
+ return false ;
156
149
}
157
- if ( bustub::StringUtil::StartsWith (line, " Projection " ) ) {
158
- if (bustub::StringUtil::Count (line , " \" ," )+ 1 > static_cast <size_t >(expected_cols_proj )) {
159
- fmt::print (" Projection wrong column pruning count!\n " );
150
+ for ( int i = 0 ; i < 2 ; i++ ) {
151
+ if (bustub::StringUtil::Count (cols[i] , " \" ," ) + 1 > static_cast <size_t >(expected_cols_agg )) {
152
+ fmt::print (" Agg wrong column pruning count!\n " );
160
153
return false ;
161
154
}
162
155
}
156
+ break ;
163
157
}
158
+ if (bustub::StringUtil::StartsWith (line, " Projection" )) {
159
+ if (bustub::StringUtil::Count (line, " \" ," ) + 1 > static_cast <size_t >(expected_cols_proj)) {
160
+ fmt::print (" Projection wrong column pruning count!\n " );
161
+ return false ;
162
+ }
163
+ }
164
+ }
164
165
} else {
165
166
throw bustub::NotImplementedException (fmt::format (" unsupported extra option: {}" , opt));
166
167
}
@@ -224,6 +225,15 @@ auto main(int argc, char **argv) -> int { // NOLINT
224
225
program.add_argument (" --verbose" ).help (" increase output verbosity" ).default_value (false ).implicit_value (true );
225
226
program.add_argument (" -d" , " --diff" ).help (" write diff file" ).default_value (false ).implicit_value (true );
226
227
program.add_argument (" --in-memory" ).help (" use in-memory backend" ).default_value (false ).implicit_value (true );
228
+ program.add_argument (" --bpm-size" )
229
+ .help (" size of the buffer pool" )
230
+ .default_value (std::to_string (bustub::BUFFER_POOL_SIZE));
231
+ program.add_argument (" --check-min-disk-write" )
232
+ .help (" the minimum disk write threshold to be checked at the end of the program" );
233
+ program.add_argument (" --check-max-disk-write" )
234
+ .help (" the maximum disk write threshold to be checked at the end of the program" );
235
+ program.add_argument (" --check-min-disk-delete" )
236
+ .help (" the maximum disk deletion threshold to be checked at the end of the program" );
227
237
228
238
try {
229
239
program.parse_args (argc, argv);
@@ -235,6 +245,8 @@ auto main(int argc, char **argv) -> int { // NOLINT
235
245
236
246
bool verbose = program.get <bool >(" verbose" );
237
247
bool diff = program.get <bool >(" diff" );
248
+ auto check_min_disk_write = program.present (" check-min-disk-write" );
249
+
238
250
std::string filename = program.get <std::string>(" file" );
239
251
std::ifstream t (filename);
240
252
@@ -253,11 +265,12 @@ auto main(int argc, char **argv) -> int { // NOLINT
253
265
}
254
266
255
267
std::unique_ptr<bustub::BusTubInstance> bustub;
268
+ size_t bpm_size = std::stoul (program.get <std::string>(" bpm-size" ));
256
269
257
270
if (program.get <bool >(" --in-memory" )) {
258
- bustub = std::make_unique<bustub::BusTubInstance>();
271
+ bustub = std::make_unique<bustub::BusTubInstance>(bpm_size );
259
272
} else {
260
- bustub = std::make_unique<bustub::BusTubInstance>(" test.bustub" );
273
+ bustub = std::make_unique<bustub::BusTubInstance>(" test.bustub" , bpm_size );
261
274
}
262
275
263
276
bustub->GenerateMockTable ();
@@ -365,5 +378,30 @@ auto main(int argc, char **argv) -> int { // NOLINT
365
378
}
366
379
}
367
380
381
+ if (program.is_used (" --check-min-disk-write" )) {
382
+ int min_disk_write_num = std::stoi (program.get (" --check-min-disk-write" ));
383
+ int actual_disk_write_num = bustub->disk_manager_ ->GetNumWrites ();
384
+ if (actual_disk_write_num < min_disk_write_num) {
385
+ fmt::print (" test incurred {} times of disk write, which is too low\n " , actual_disk_write_num);
386
+ return 1 ;
387
+ }
388
+ }
389
+ if (program.is_used (" --check-max-disk-write" )) {
390
+ int max_disk_write_num = std::stoi (program.get (" --check-max-disk-write" ));
391
+ int actual_disk_write_num = bustub->disk_manager_ ->GetNumWrites ();
392
+ if (actual_disk_write_num > max_disk_write_num) {
393
+ fmt::print (" test incurred {} times of disk write, which is too high\n " , actual_disk_write_num);
394
+ return 1 ;
395
+ }
396
+ }
397
+ if (program.is_used (" --check-min-disk-delete" )) {
398
+ int min_disk_delete_num = std::stoi (program.get (" --check-min-disk-delete" ));
399
+ int actual_disk_delete_num = bustub->disk_manager_ ->GetNumDeletes ();
400
+ if (actual_disk_delete_num < min_disk_delete_num) {
401
+ fmt::print (" test incurred {} times of disk deletion, which is too low\n " , actual_disk_delete_num);
402
+ return 1 ;
403
+ }
404
+ }
405
+
368
406
return 0 ;
369
407
}
0 commit comments