How to test mutex

I am trying to understand mutex practically with ESP32. How to test mutex for freertos

void setup()
{
  Serial.begin(112500);
  /* Create two tasks. */
  xTaskCreate( vTask1, "Task 1", 10000, NULL, 1, NULL); 
  xTaskCreate( vTask2, "Task 2", 10000, NULL, 1, NULL); 
}


void loop() {
  // Do nothing

}

void vTask1( void *pvParameters )
{
  /* As per most tasks, this task is implemented in an infinite loop. */
  for(;;)
  {
    Serial.println("Task 1 is running");
   
   }
}

void vTask2( void *pvParameters )
{
  
  for(;;)
  {
    Serial.println("Task 2 is running");
  
   }
}

Sorry but your question is not clear as the code you show doesn’t use a mutex. Do you want to protect the calls to Serial.println() using a mutex? Here are some references to start with:
About mutexes: https://freertos.org/Real-time-embedded-RTOS-mutexes.html
Mutex API, including example code: https://freertos.org/a00113.html

As I understand if there is single resource available and more than two Tasks need to access resource, then mutex need to be used

What is resource in this situations ?

Is the I2C, SPI UART called resource in this situation?

If not then what are the resources that we lock and unlock

Resource is a general term used for anything that must not be accessed by two tasks at the same time. This can be peripherals like I2C, SPI or UART or can just be a variable.

Mutexes are not always the best mechanism to protect any resource that needs to be shared - it depends how long accessing the resource is going to take. Also, if you are just accessing a variable, you may not need to protect the variable at all if the tasks are just reading it.

Do you always use a mutex whenever two tasks share these peripherals?

It will be easier to understand if you can give real situation in which mutex is used.

I’d recommend reading this book - https://www.freertos.org/fr-content-src/uploads/2018/07/161204_Mastering_the_FreeRTOS_Real_Time_Kernel-A_Hands-On_Tutorial_Guide.pdf