OBD tells whether I have passed the emission test or not. I want to know the formula by which it calculates the rate of CO, NOx, HC emission from my car and compares it with some set threshold value to give a pass/fail result. The formula will be different for Petrol (gasoline) and Diesel cars, I guess.
I think you miss-understand how OBD tells that your car is passing emissions.
All the car does is make sure that the emissions control systems are functioning and then it hopes that what is coming out of the tail pipe is OK. The car verifies that the fuel mixture is within tolerance, that the EGR is functioning, that the evaporative emissions system has no holes and is purging, that the catalytic converter can store adequate amounts of oxygen and that all the electrical components are functional.
Beyond that there is nothing else. The car could be pouring out mad amounts of NOx but never know about it if all the systems are functional.
The EGR system is verified by checking it's flow either directly or indirectly. If there is a correct amount of flow then the system is deemed functional. Ford uses a DPFE sensor that checks the flow of the EGR directly. Other cars use the MAP sensor to indirectly check EGR flow. By activating the EGR valve there should be a notable drop in the manifold vacuum. If there is too much flow then the the valve is stuck open. If there is too little flow or no flow then something is wrong.
The EVAP system is checked for leaks and flow. There are literally hundreds of different ways to check this. The most commons is using a vent solenoid, purge solenoid and EVAP pressure sensor. The system is sealed with the vent solenoid. Then activating the purge solenoid (while the engine is running) will pull the system into a light vacuum. This vacuum is read my the pressure sensor. If the system is capable of achieving a vacuum means that purge flow is sufficient. Once a vacuum is achieved then the the purge solenoid stops. The system will then watch the rate of decay. If the rate of decay is slow then the system is good. If the decay is high then there is a hole of some sorts. If a vacuum can not be achieved at all then there is a huge hole or the purge solenoid is not working.
The fuel system is checked with the oxygen sensors. The oxygen sensors verify if too much too little or just the right amount of fuel is being added. This amount is reflected in the long term fuel trim numbers. If the numbers are around zero then everything is good. If the numbers are very negative (depends on vehicle but under -12% would do it) the system is running too rich. If the numbers are very positive (over 12%) the the system is too lean.
Similar to the EVAP system there are lots of ways to check the the catalytic converter. The catalytic converter has an oxygen sensor down stream of it. By comparing the upstream and down stream oxygen sensors the oxygen storage capability of the converter can be checked.
If you manage to get the fuel consumption from the OBDII data, you can calculate the amount of CO2 emitted. (How to calculate petrol consumption (roghly) from OBDII data)
Since fossile fuel is a mixture of different hydrogencarbons, it is inevitable that its combustion generates CO2. I found 2.32kg per liter petrol and 2.62kg per liter diesel, but this numbers may vary due to variations of the composition (e.g. additional ethanol) and temperature (volume expands with temperature). However, these values give a good hint.
All the other emissions inadvertent by-products. A tiny fraction of the fuel may not be burned completely, causing some CO and/or unburned carbon/fuel. Too much air causes CO, and since the oxygen starts to react with the nitrogen of the air, NOx. The amount of emissions depends on the motor design and load / environmental conditions. May be the manufacturer has a table of this, but you won't get it.
Also, the car doesn't measure them. For example, the actual VW emission scandal is about NOx and was discovered when testing a newly developed, mobile NOx measurement device. It wasn't possible to measure NOx while driving on the road before.
The lambda-sensor measures the amount of remaining oxygen in the exhaust gas, so the car can adjust the air/fuel ratio to make the combustion as perfect as possible, but it can't fully avoid nor measure this emissions.