Threads tests WIP
This commit is contained in:
parent
e5a765409a
commit
e2ca9b5318
5 changed files with 109 additions and 1 deletions
49
tests/stack_trace.test.vim
Normal file
49
tests/stack_trace.test.vim
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
let s:fn='testdata/cpp/simple/threads.cpp'
|
||||||
|
|
||||||
|
function! SetUp()
|
||||||
|
call vimspector#test#setup#SetUpWithMappings( 'HUMAN' )
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! ClearDown()
|
||||||
|
call vimspector#test#setup#ClearDown()
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:StartDebugging()
|
||||||
|
exe 'edit ' . s:fn
|
||||||
|
call vimspector#SetLineBreakpoint( s:fn, 13 )
|
||||||
|
call vimspector#Launch()
|
||||||
|
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 13, 1 )
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! Test_Multiple_Threads()
|
||||||
|
call vimspector#SetLineBreakpoint( s:fn, 41 )
|
||||||
|
call vimspector#SetLineBreakpoint( s:fn, 51 )
|
||||||
|
call s:StartDebugging()
|
||||||
|
|
||||||
|
call vimspector#Continue()
|
||||||
|
|
||||||
|
" As we step through the thread creation we should get Thread events
|
||||||
|
|
||||||
|
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 41, 1 )
|
||||||
|
call vimspector#Continue()
|
||||||
|
|
||||||
|
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 41, 1 )
|
||||||
|
call vimspector#Continue()
|
||||||
|
|
||||||
|
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 41, 1 )
|
||||||
|
call vimspector#Continue()
|
||||||
|
|
||||||
|
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 41, 1 )
|
||||||
|
call vimspector#Continue()
|
||||||
|
|
||||||
|
" This is the last one
|
||||||
|
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 41, 1 )
|
||||||
|
call vimspector#Continue()
|
||||||
|
|
||||||
|
" So we break out of the loop
|
||||||
|
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 51, 1 )
|
||||||
|
|
||||||
|
call vimspector#ClearBreakpoints()
|
||||||
|
call vimspector#test#setup#Reset()
|
||||||
|
%bwipe!
|
||||||
|
endfunction
|
||||||
1
tests/testdata/cpp/simple/.gitignore
vendored
1
tests/testdata/cpp/simple/.gitignore
vendored
|
|
@ -2,3 +2,4 @@ simple
|
||||||
variables
|
variables
|
||||||
struct
|
struct
|
||||||
printer
|
printer
|
||||||
|
threads
|
||||||
|
|
|
||||||
1
tests/testdata/cpp/simple/.ycm_extra_conf.py
vendored
1
tests/testdata/cpp/simple/.ycm_extra_conf.py
vendored
|
|
@ -2,6 +2,7 @@ def Settings( **kwargs ):
|
||||||
return {
|
return {
|
||||||
'flags': [
|
'flags': [
|
||||||
'-x', 'c++',
|
'-x', 'c++',
|
||||||
|
'-std=c++17',
|
||||||
'-Wextra', '-Werror', '-Wall'
|
'-Wextra', '-Werror', '-Wall'
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
tests/testdata/cpp/simple/Makefile
vendored
2
tests/testdata/cpp/simple/Makefile
vendored
|
|
@ -2,7 +2,7 @@ CXXFLAGS=-g -O0 -std=c++17
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
|
|
||||||
TARGETS=simple variables struct printer
|
TARGETS=simple variables struct printer threads
|
||||||
|
|
||||||
all: $(TARGETS)
|
all: $(TARGETS)
|
||||||
|
|
||||||
|
|
|
||||||
57
tests/testdata/cpp/simple/threads.cpp
vendored
Normal file
57
tests/testdata/cpp/simple/threads.cpp
vendored
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
#include <chrono>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string_view>
|
||||||
|
#include <system_error>
|
||||||
|
#include <thread>
|
||||||
|
#include <vector>
|
||||||
|
#include <charconv>
|
||||||
|
#include <random>
|
||||||
|
|
||||||
|
int main( int argc, char ** argv )
|
||||||
|
{
|
||||||
|
int numThreads = {};
|
||||||
|
if ( argc < 2 )
|
||||||
|
{
|
||||||
|
numThreads = 5;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::string_view numThreadArg( argv[ 1 ] );
|
||||||
|
if ( auto [ p, ec ] = std::from_chars( numThreadArg.begin(),
|
||||||
|
numThreadArg.end(),
|
||||||
|
numThreads );
|
||||||
|
ec != std::errc() )
|
||||||
|
{
|
||||||
|
std::cerr << "Usage " << argv[ 0 ] << " <number of threads>\n";
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Creating " << numThreads << " threads" << '\n';
|
||||||
|
|
||||||
|
std::vector<std::thread> threads{};
|
||||||
|
threads.reserve( numThreads );
|
||||||
|
|
||||||
|
auto eng = std::default_random_engine() ;
|
||||||
|
auto dist = std::uniform_int_distribution<int>( 250, 1000 );
|
||||||
|
|
||||||
|
for ( int i = 0; i < numThreads; ++i )
|
||||||
|
{
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
threads.emplace_back( [&,tnum=i]() {
|
||||||
|
std::cout << "Started thread " << tnum << '\n';
|
||||||
|
std::this_thread::sleep_for(
|
||||||
|
5s + std::chrono::milliseconds( dist( eng ) ) );
|
||||||
|
std::cout << "Completed thread " << tnum << '\n';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for ( int i = 0; i < numThreads; ++i )
|
||||||
|
{
|
||||||
|
threads[ i ].join();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue