--source include/linux.inc
--source include/not_embedded.inc
--source include/have_perfschema.inc

--source include/count_sessions.inc

# creating several connections in order to have more than one record in the processlist
--connect (connection_one,localhost,root,,)
--connect (connection_two,localhost,root,,)
--connect (connection_three,localhost,root,,)

--connection default

--disable_query_log

# creating a table to store LWP ids of the current process
CREATE TABLE lwp_table(lwp_no INT);

# extracting current process id file name from the @@pid_file
--let $pid_file=`SELECT @@pid_file`

# filling lwp_table with values returned from "ps" system call
# "--no-header" means omitting column names in output (just plain numbers)
# "-L" means include lightweight threads
# "-p $mysqld_pid" means only output LWPs which belolng to the specified process id
# "-o lwp" means output only LWP id
--let $ps_result_file=$MYSQLTEST_VARDIR/percona_ps_result
--exec ps --no-headers -L -p `cat $pid_file` -o lwp > $ps_result_file
--eval LOAD DATA LOCAL INFILE '$ps_result_file' INTO TABLE lwp_table

--enable_query_log

# checking that all Tids from the current connections can be found in the "ps" list
# the result of the COUNT(*) is expected to be 0
SELECT COUNT(*) = 0 AS must_be_true FROM performance_schema.threads WHERE thread_os_id NOT IN (SELECT lwp_no FROM lwp_table);

--disable_query_log

# temporary table cleanup
DROP TABLE lwp_table;

--enable_query_log

# dropping auxiliary connections
--disconnect connection_one
--disconnect connection_two
--disconnect connection_three

--source include/wait_until_count_sessions.inc

# removing temporary file generated by system "ps" call
--remove_file $ps_result_file
