[sanitizer] Add basic qsort test

This commit is contained in:
Vitaly Buka 2021-08-26 12:02:45 -07:00
parent 3d85342982
commit 96fa1eaae4
1 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,24 @@
// RUN: %clangxx -O2 %s -o %t
#include <algorithm>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
static int compare_ints(const void *a, const void *b) {
return *(const int *)b - *(const int *)a;
}
int main() {
std::vector<int> nums(100000);
for (auto &n : nums)
n = rand();
std::vector<int> to_qsort = nums;
qsort(to_qsort.data(), to_qsort.size(), sizeof(to_qsort[0]), &compare_ints);
std::sort(nums.begin(), nums.end());
assert(nums == to_qsort);
}