Much of chemical analysis in the age of alchemy was done by taste and smell. Yes, this was very hazardous.
First thing is that anyone with a good sample will notice the sulfurous smell of gunpowder. The black color (and the way it leaves black dust when it's handled) would suggest charcoal is involved.
As @L.Dutch suggested, the taste of potassium nitrate is quite distinctive (to an alchemist, anyway) -- sal petre or "rock salt" was well known in Europe before the secrets of making gunpowder found their way from China to the west; it was used to make nitric acid.
Once those three ingredients are known, it would be a matter of testing known to alchemists (in our timeline) before 1300 CE to get a pretty close idea of the proportions.
Then comes the hard part. If you just mix the ingredients, even in perfect proportion, the product will just burn (sorry, Captain Kirk, if the diamonds didn't nix your bamboo cannon, the burn rate would). Instead, one must grind the saltpeter and sulfur into the pore in the charcoal, a process usually done with the "green powder" kept damp -- both to reduce the risk of ignition from friction, and as an aid to getting the saltpeter inside the charcoal. This makes what was called "serpentine" powder (probably because one of the early guns was a serpentine, referring to the shape of the holder for the glowing match).
Once everything has been ground to the point where the ingredients can't be separated, then one must press the powder -- again, done damp, this makes a hard cake which, when thoroughly dried, is broken up and sieved to size the granules. This is "corning" and produces powder that would serve well through the 19th century -- essentially similar to what's still sold today (except modern powder gets one additional step, tumbling with graphite to coat the granules, making them meter more smoothly and offering slight protection against accidental ignition by static sparks).
In our history, it took more than two centuries for powder (at least in the West) to progress from "fireworks" to gun propellant, and that was after Westerners in the late 13th century had learned from traders what the Chinese put in their powder (which, by then, the Chinese were using in war rockets and small bombs, perhaps even primitive guns).