<commit_before>#include <iostream>
#include <pthread.h>
#include <stdlib.h>
#include <math.h>
#include <sstream>
#include "capi.h"
#include "mcp_api.h"
#include "user_api.h"
#include "cache_state.h"
#include "dram_directory_entry.h"
#include "core.h"
#include "chip.h"
#include "pin.H"

using namespace std;

pthread_mutex_t write_lock;
UINT32* global_array_ptr;

#define DEBUG 1
#define TEST_MEMORY_SIZE (pow(2,30))

// FIXME: Modifications
#define STATE_COUNT 6
#define TEST_COUNT 24

//count the number of tests performed
//output it for each test
int test_count = 0;
int tests_passed = 0;
int tests_failed = 0;

#ifdef DEBUG
pthread_mutex_t lock;
#endif

#define CORE_COUNT 2

enum operation_t {
	CORE_0_READ_OP,
	CORE_0_WRITE_OP,
	CORE_1_READ_OP,
	CORE_1_WRITE_OP,
	OPERATION_COUNT
};

struct addrVectStruct {
	ADDRINT addr;
	int dram_home_id;
};

struct testStateStruct {
	DramDirectoryEntry::dstate_t dstate;
	CacheState::cstate_t cstate0;
	CacheState::cstate_t cstate1;
};


/* The final memory state for every test is stored
 * in a number of 'fini_vector' arrays.  It is important
 * to know which tests correspond to which core.
 * therefore, for 52 tests, the first 26 correspond
 * to core#0, and the last 26 correspond to core#1
 */ 

vector<string> test_code_vector; //store a string of the "Initial Mem State", 
vector<string> fini_state_str_vector; //store a string of the "Final Mem State", for debug purposes (" SSI-{0}"
vector<operation_t> operation_vector;
vector<addrVectStruct> address_vector;
vector<testStateStruct> init_test_state_vector;
vector<testStateStruct> fini_test_state_vector;
vector< vector<UINT32> > init_sharers_vector;
vector< vector<UINT32> > fini_sharers_vector;

vector<char*> fini_dram_block_vector;
vector<char*> init_cache_block_vector;
vector<char*> fini_cache_block_vector;

char* dramBlock;
char* cacheBlockS;
char* cacheBlockSW;
char* cacheBlockE;
char* cacheBlockEW;

UINT32 cacheBlockSize;

vector<UINT32> fini_mem_state_id; //allow the "fini state arrays to point to the init state arrays

//dynamically set these values to point
//to valid addresses on dram0, dram1 sections
ADDRINT dram0_address, dram1_address;

//vector<stringstream> error_str_vector;

// Function executed by each thread
// each thread "starts" here
void* starter_function(void *threadid);

void awesome_test_suite_msi(int tid); 

void initialize_test_parameters();

int main(int argc, char* argv[]) { // main begins

	if (argc != 2) {
		cerr << "[Usage]: ./test <logCacheBlockSize>\n";
	}
	 
	// Declare threads and related variables
	
	// 2 important Simulator variables are initialized here
	UINT32 logCacheBlockSize;

	initMCP();

	sharedMemThreadsInit();

	logCacheBlockSize = atoi(argv[1]);
	cacheBlockSize = 1 << logCacheBlockSize;
	
	pthread_t threads[2];
	pthread_attr_t attr;
	
#ifdef DEBUG
	cerr << "This is the function main()" << endl;
#endif
	// Initialize global variables
	global_array_ptr = new UINT32[(UINT64) TEST_MEMORY_SIZE/ (sizeof(UINT32)) ];
	cerr << "What is the Number of Elements that are being made? = " << (((int) TEST_MEMORY_SIZE/(sizeof(UINT32)))) << endl;
//	global_array_ptr = new UINT64[BAJILLION];

#ifdef DEBUG
	cerr << "Initializing thread structures" << endl << endl;
	pthread_mutex_init(&lock, NULL);
#endif

	// Initialize threads and related variables
	pthread_attr_init(&attr);
	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
	pthread_mutex_init(&write_lock, NULL);

	initialize_test_parameters();

#ifdef DEBUG
	cerr << "Spawning threads" << endl << endl;
#endif

   pthread_create(&threads[0], &attr, starter_function, (void *) 0);    
   pthread_create(&threads[1], &attr, starter_function, (void *) 1);    

#ifdef DEBUG
//   pthread_mutex_lock(&lock);
	cerr << "Waiting to join" << endl << endl;
//   pthread_mutex_unlock(&lock);
#endif

	// Wait for all threads to complete
   pthread_join(threads[0], NULL);         
	pthread_join(threads[1], NULL);

	sharedMemThreadsFinish();

	cerr << "Shared Memory Threads Joined\n";

	quitMCP();

#ifdef DEBUG
	cerr << "End of execution" << endl << endl;
#endif
        
   return 0;
} // main ends

//spawned threads run this function
void* starter_function(void *threadid)
{
	int tid;
	CAPI_Initialize_FreeRank(&tid);

#ifdef DEBUG  
   pthread_mutex_lock(&lock);
	cerr << "executing do_nothing function: " << tid << endl << endl;
   pthread_mutex_unlock(&lock);
#endif
   
   if(tid==0) {
		cerr << "Executing awesome test suite Core # 0 " << endl;
		awesome_test_suite_msi(tid);
		cerr << "FInished Executing awesome test suite  Core #0" << endl;
   } else {
		cerr << "Executing awesome test suite Core #1 " << endl;
		awesome_test_suite_msi(tid);
		cerr << "FInished Executing awesome test suite  Core #1" << endl;<commit_msg>[tests] Update the shared memory test to the new carbonInit / carbonFinish functions so that the MCP quits properly.<commit_after>#include <iostream>
#include <pthread.h>
#include <stdlib.h>
#include <math.h>
#include <sstream>
#include "capi.h"
#include "mcp_api.h"
#include "user_api.h"
#include "cache_state.h"
#include "dram_directory_entry.h"
#include "core.h"
#include "chip.h"
#include "pin.H"

using namespace std;

pthread_mutex_t write_lock;
UINT32* global_array_ptr;

#define DEBUG 1
#define TEST_MEMORY_SIZE (pow(2,30))

// FIXME: Modifications
#define STATE_COUNT 6
#define TEST_COUNT 24

//count the number of tests performed
//output it for each test
int test_count = 0;
int tests_passed = 0;
int tests_failed = 0;

#ifdef DEBUG
pthread_mutex_t lock;
#endif

#define CORE_COUNT 2

enum operation_t {
	CORE_0_READ_OP,
	CORE_0_WRITE_OP,
	CORE_1_READ_OP,
	CORE_1_WRITE_OP,
	OPERATION_COUNT
};

struct addrVectStruct {
	ADDRINT addr;
	int dram_home_id;
};

struct testStateStruct {
	DramDirectoryEntry::dstate_t dstate;
	CacheState::cstate_t cstate0;
	CacheState::cstate_t cstate1;
};


/* The final memory state for every test is stored
 * in a number of 'fini_vector' arrays.  It is important
 * to know which tests correspond to which core.
 * therefore, for 52 tests, the first 26 correspond
 * to core#0, and the last 26 correspond to core#1
 */ 

vector<string> test_code_vector; //store a string of the "Initial Mem State", 
vector<string> fini_state_str_vector; //store a string of the "Final Mem State", for debug purposes (" SSI-{0}"
vector<operation_t> operation_vector;
vector<addrVectStruct> address_vector;
vector<testStateStruct> init_test_state_vector;
vector<testStateStruct> fini_test_state_vector;
vector< vector<UINT32> > init_sharers_vector;
vector< vector<UINT32> > fini_sharers_vector;

vector<char*> fini_dram_block_vector;
vector<char*> init_cache_block_vector;
vector<char*> fini_cache_block_vector;

char* dramBlock;
char* cacheBlockS;
char* cacheBlockSW;
char* cacheBlockE;
char* cacheBlockEW;

UINT32 cacheBlockSize;

vector<UINT32> fini_mem_state_id; //allow the "fini state arrays to point to the init state arrays

//dynamically set these values to point
//to valid addresses on dram0, dram1 sections
ADDRINT dram0_address, dram1_address;

//vector<stringstream> error_str_vector;

// Function executed by each thread
// each thread "starts" here
void* starter_function(void *threadid);

void awesome_test_suite_msi(int tid); 

void initialize_test_parameters();

int main(int argc, char* argv[]) { // main begins

	if (argc != 2) {
		cerr << "[Usage]: ./test <logCacheBlockSize>\n";
	}
	 
	// Declare threads and related variables
	
	// 2 important Simulator variables are initialized here
	UINT32 logCacheBlockSize;

	carbonInit();

	logCacheBlockSize = atoi(argv[1]);
	cacheBlockSize = 1 << logCacheBlockSize;
	
	pthread_t threads[2];
	pthread_attr_t attr;
	
#ifdef DEBUG
	cerr << "This is the function main()" << endl;
#endif
	// Initialize global variables
	global_array_ptr = new UINT32[(UINT64) TEST_MEMORY_SIZE/ (sizeof(UINT32)) ];
	cerr << "What is the Number of Elements that are being made? = " << (((int) TEST_MEMORY_SIZE/(sizeof(UINT32)))) << endl;
//	global_array_ptr = new UINT64[BAJILLION];

#ifdef DEBUG
	cerr << "Initializing thread structures" << endl << endl;
	pthread_mutex_init(&lock, NULL);
#endif

	// Initialize threads and related variables
	pthread_attr_init(&attr);
	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
	pthread_mutex_init(&write_lock, NULL);

	initialize_test_parameters();

#ifdef DEBUG
	cerr << "Spawning threads" << endl << endl;
#endif

   pthread_create(&threads[0], &attr, starter_function, (void *) 0);    
   pthread_create(&threads[1], &attr, starter_function, (void *) 1);    

#ifdef DEBUG
//   pthread_mutex_lock(&lock);
	cerr << "Waiting to join" << endl << endl;
//   pthread_mutex_unlock(&lock);
#endif

	// Wait for all threads to complete
   pthread_join(threads[0], NULL);         
	pthread_join(threads[1], NULL);


   carbonFinish();

#ifdef DEBUG
	cerr << "End of execution" << endl << endl;
#endif
        
   return 0;
} // main ends

//spawned threads run this function
void* starter_function(void *threadid)
{
	int tid;
	CAPI_Initialize_FreeRank(&tid);

#ifdef DEBUG  
   pthread_mutex_lock(&lock);
	cerr << "executing do_nothing function: " << tid << endl << endl;
   pthread_mutex_unlock(&lock);
#endif
   
   if(tid==0) {
		cerr << "Executing awesome test suite Core # 0 " << endl;
		awesome_test_suite_msi(tid);
		cerr << "FInished Executing awesome test suite  Core #0" << endl;
   } else {
		cerr << "Executing awesome test suite Core #1 " << endl;
		awesome_test_suite_msi(tid);
		cerr << "FInished Executing awesome test suite  Core #1" << endl;
{'fraction_non_alphanumeric': 0.11369834277323264, 'fraction_numerical': 0.0144745122718691, 'mean_word_length': 5.023373341756159, 'pattern_counts': {'":': 0, '<': 171, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '398721', 'n_tokens_mistral': 3375, 'n_tokens_neox': 3222, 'n_words': 929}